0

I add the following line to the red-hat crontab

in order to run the script /var/scripts/info_from_all_sites.bash every Friday at 00:00 night

script should get as argument the file - /var/RT/names.txt

so script will read all info from this file,

 0 0 * * 5   /var/scripts/info_from_all_sites.bash /var/RT/names.txt 1>/dev/null 2>&1

my question is - is it OK to add the file as argument to the script in the crontab ?

Or maybe I need to put the file with double quotes as

 0 0 * * 5   /var/scripts/info_from_all_sites.bash "/var/RT/names.txt" ?
1
  • @Rahul Why would that be a good thing? – Kusalananda Jul 12 '16 at 10:16
0

Yes, it is ok to do this.

From the crontab(5) manual:

The "sixth" field (the rest of the line) specifies the command to be run. The entire command portion of the line, up to a newline or a % character, will be executed by /bin/sh or by the shell specified in the SHELL variable of the cronfile. A % character in the command, unless escaped with a backslash (\), will be changed into newline characters, and all data after the first % will be sent to the command as standard input.

0

I was having this same issue where I was using the following crontab:

0 23 * * * sudo -u myname /home/myname/bin/buildme.sh -f >> /home/myname/log.txt

And inside the bash script I was using this to get the -f option:

while getopts ":f" opt; do
    case $opt in
        f)
            force_full=1
            ;;
        \?)
            echo "Invalid option: -$OPTARG" >&2
            ;;
    esac
done

So I noticed that the option wasn't being honored when I ran this through cron for some reason. Well, adding /bin/bash to the cronjob fixed it right up. The new crontab is:

0 23 * * * sudo -u myname /bin/bash /home/myname/bin/buildme.sh -f >> /home/myname/log.txt

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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