Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Can someone give me an example that shows how to put Cron commands into a script? Using these commands as an example:

find /home/network/public_1 -type f -ctime -1 -exec ls -ls {} \;
find /home/network/public_2 -type f -ctime -1 -exec ls -ls {} \;
find /home/network/public_3 -type f -ctime -1 -exec ls -ls {} \;

These commands work okay when I run them separately on CPanel's Cron menu. But they do not run when I put them together in a script and then try to execute the script as a single Cron job. The script probably requires different syntax, but I have not been able to figure out how to do this.

share|improve this question
    
You may need to escape the backslash with another backslash. Alternatively use + instead of \; so that ls is executed with multiple arguments which is more efficient. Finally you could list all three start directories in one find command. –  wurtel Sep 25 '14 at 14:01
    
What do you mean by "escape the backslash with another backslash"? Can you give me an example? I tried starting the script with #!/bin/sh (suggested below) but that didn't fix the problem. –  MaJ Sep 26 '14 at 16:50

1 Answer 1

The script would need to be marked as executable by the cron process in the filesystem, and you would need to provide the full path to the script.

Also, you need to begin your script with this:

#!/bin/sh

which tells the OS what to run as the interpreter.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.