scripts: Fix shell expansion when collecting VM logs

The [[:digit:]] does not work correctly when using sudo

 2018-10-04 14:31:33.319558 | opensuse-423 | + sudo cp '/var/log/libvirt/baremetal_logs/testvm[[:digit:]]_console.log' /home/zuul/workspace/logs
 2018-10-04 14:31:33.328756 | opensuse-423 | cp: cannot stat '/var/log/libvirt/baremetal_logs/testvm[[:digit:]]_console.log': No such file or directory

As we can see [[:digit:]] is not expanded so no logs are collected. This
is because the expansion happens by the user but since he does not have
access to the directory the command fails. We can fix this by opening a
subshell so it gets run with sudo privileges.

Change-Id: Ibdf8606a3b72c48faffdf2b58b122b690008ba98
This commit is contained in:
Markos Chandras 2018-10-05 14:29:34 +01:00
parent b7696ca200
commit 431b768929
1 changed files with 1 additions and 1 deletions

View File

@ -14,7 +14,7 @@ echo "Making logs directory and collecting logs."
[ -d ${LOG_LOCATION} ] || mkdir -p ${LOG_LOCATION}
if [ -z "${TEST_VM_NODE_NAMES+x}" ]; then
sudo cp /var/log/libvirt/baremetal_logs/testvm[[:digit:]]_console.log ${LOG_LOCATION}
sudo sh -c "cp /var/log/libvirt/baremetal_logs/testvm[[:digit:]]_console.log" ${LOG_LOCATION}
sudo chown $USER ${LOG_LOCATION}/testvm[[:digit:]]_console.log
sudo chmod o+r ${LOG_LOCATION}/testvm[[:digit:]]_console.log
else