简体   繁体   中英

Start bash script from bash script as cronjob

I'm trying to start a bash script(test.sh) from a second bash script that runs as a cronjob(startTest.sh) on Ubuntu 14.04. Cron is running and both scripts work perfectly if called from command line.

startTest.sh looks like this:

#!bin/bash
SHELL=/bin/bash
PATH=/usr/local/bin:/usr/local/sbin:/sbin:/usr/sbin:/bin:/usr/bin:/home/username/path/to/script

bash /home/username/path/to/script/test.sh

test.sh looks like this:

#!/bin/bash

touch it_works.txt

My crontab entry looks like this

* * * * * /usr/local/bin/startTest.sh

Best practice is generally not to use relative paths (unless you do an explicit cd ) in scripts run as cron jobs.

crond is probably not running from whatever directory you expect it to. Depending on what user this cron job runs as, the script either does not have permission to create it_works.txt in crond 's current working directory, or it is creating the file and you're looking in the wrong place.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM