开发者

change directory and run command with #!bin/bash file

开发者 https://www.devze.com 2023-03-30 20:22 出处:网络
I need a cron job which changes the directory and runs a command. Commands: cd /var/www/domain.com/httpdocs

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 "chmod开发者_JS百科ed" 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 your cd command. 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, dos2unix converts files in place.)


Does directory /var/www/domain.com/httpdocs actually exist? Can you manually cd /var/www/domain.com/httpdocs from a shell on that system without error?

0

精彩评论

暂无评论...
验证码 换一张
取 消