Showing results for 
Search instead for 
Did you mean: 
Post a Question

Calling a Bash Script in Cron


I'm trying to scheddule a cronjob (bash script) in our management station. Such bash script, when executed manually, works flawlesly, but when scheduled over cron, it does not work. sk77300 and sk90441 have not helped at all.

Any other ideas?

14 Replies

Re: Bash Script

1. Please check if cron daemon is running.

2. Please check if your script ends with the newline.

0 Kudos

Re: Bash Script

Keep in mind some environment variables in the script may not be defined in the environment that runs the cron script.

It would be helpful if you could provide the errors you're getting.

Re: Bash Script

Hi Dameon

No errors at all in /var/log/cron. any other file i should be looking at?


0 Kudos

Re: Bash Script

Are you explicitly declaring the command interpreter (i.e. magic number) at the start of the shell script like this:

#!/bin/bash -f

If so, try adding -x like this:

#!/bin/bash -f -x

-x causes every command being executed by the script and its arguments to be output as it happens.  Very helpful for troubleshooting.  Also make sure that any commands being invoked in the script are using absolute paths (i.e. /bin/ls) and try to avoid using relative paths and paths referencing an environment variable such as $FWDIR/bin/ until you figure out what is wrong.

My book "Max Power: Check Point Firewall Performance Optimization"
now available via

"IPS Immersion Training" Self-paced Video Class
Now Available at

Re: Bash Script

If you need  to load the environment variables:  "source /etc/profile.d/"

0 Kudos

Re: Bash Script

Hi Luis

The line is in the script.

@Tim: Those options are not recognized:

/bin/bash: - : invalid option

I had $MDSVERUTIL in my script, which i exchanged with /opt/CPmds-R77/system/shared/MDSVerUtil.  Situation is still the same when script is run over Cron (which is active), and running it manually gives no problem

0 Kudos

Re: Bash Script

What errors do you get? Make sure you sent the output of the script execution to a file where you can see the errors

0 Kudos

Re: Bash Script

Not sure if this helps... Be sure to write the full path of all commands into cron and/or script invoked.

Refer to:

difference between cron and command line environment? shell script errors 

0 Kudos

Re: Bash Script

The below produces no out put at all:

*/5 * * * * /home/indeni/ >> /home/indeni/session.txt 2>&1

0 Kudos

Re: Bash Script

As which user are you adding this crontab job?

Does that use have sufficient access rights?

Keep in minds we have zero knowledge of what you have done or what your setup looks like. Unless you tell us we simply don't know.

0 Kudos

Re: Bash Script

Can you show us the script?

What "source" line do you use?

Re: Bash Script

If you see nothing at /home/indeni/session.txt it is probably because cron is not running your script.

0 Kudos

Re: Bash Script

This is how we run scripts from cron, in clish add the following command:

add cron job MDS_backup command "/backup/scripts/FWBackupMDS >/dev/null 2>&1" recurrence daily time 1:00

The  >/dev/null 2>&1 makes sure the output is redirected properly. On the first line of the script put this line:


After that all other things you need to do.

<crontab -l> shows me:

# Generated by /bin/cron_xlate on Mon Aug 7 08:42:47 2017
# mins hrs daysinm months daysinw command

00 1 * * * /backup/scripts/FWBackupMDS >/dev/null 2>&1

Regards, Maarten
0 Kudos

Re: Bash Script

@Ignacio Garcia: I am not sure if the problem was resolved?
When a script doesn't run as a cronjob, then the reason is almost always one of three things:
1) The cronjob user does not have the Bash shell set as default, or
2) the CP environment parameters is not loading correctly.
On rare occations I have experienced that one must run the command "dos2unix *.sh" to get the cronjob working.

I recently discovered that sk77300 is no longer correct.
Changing the <version> parameter to R80 only works with R80 and R80.10
source /opt/CPshrd-R80/tmp/

When using R80.20 it must look like this:
source /opt/CPshrd-R80.20/tmp/


Hope this helps! Smiley Happy