[SOLVED] Running "qm start" in a cron shell script

fibo_fr

Member
Apr 21, 2014
40
2
8
Remoulins, France
I face a stupid problem:
- I want to run "qm start 800" in a bash script
- this works fine when I run directly the shell
- but does not work when the same script is placed as a cron job.

- the job is created and run by root
- I have tested the usual tricks in such situarions, with and without sudo

so te command line is presently
$(qm config) start 800
 
Last edited:
$(qm config) start 8000
that looks wrong - the output of `qm config` will be the error message that you need to provide a VMID

my guess is that qm is not in the PATH, when run via cron
try calling it with the absolute path `/usr/sbin/qm`
 
  • Like
Reactions: _gabriel
oops, sorrr, typo!

I meant
$(which qm) start 800

the construct $(which command) returns command with its full path... so it is expected to be portable between diffrent machines.
however, this proved not to work.

I used the full path and then it worked.

Strange: in all my other uses of $(which it worked while no using did not work...

Thx anyway!
 
ah - ok that makes more sense.
`which` looks for the command in all directories in the PATH - in a root interactive shell the PATH contains:
Code:
root@pve:/root# set |grep ^PATH
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

in cron-jobs the PATH is
Code:
PATH=/usr/local/bin:/usr/bin:/bin

and qm is not in there.

anyways - glad it worked out :)
 
  • Like
Reactions: akanealw