I need a cron job which changes the directory and runs a command.
Commands:
cd /var/www/domain.com/httpdocs
sake cron/test
I wrote this .sh file (/var/here/and/there/test.sh):
#!/bin/bash
cd /var/www/domain.com/httpdocs
sake cron/test
I “chmoded” the file:
chmod 777 test.sh
When I run it:
sh /var/here/and/there/test.sh
the output is this:
[1] : No such file or directoryrons/test.sh: line 2: cd: /var/www/domain.com/httpdocs
[2] Can't find ./sapphire/cli-script.php or ./cli-script.php
(the second line is from the sake command, which only is successfull when executed in the correct directory)
thx
I think you have a stray carriage return (
\r) at the end of yourcdcommand. The shell assumes the'\r'is part of the directory name. When it prints it in the error message, the cursor jumps to the beginning of the line, and the remainder of the message overwrites whatever was there.Make sure that test.sh uses Unix-style line endings, not Windows-style endings. (This may be a side effect of whatever editor you used to create it.)
Are you running under Cygwin by any chance?
dos2unix --help(Warning: Unlike most filters,
dos2unixconverts files in place.)