简体   繁体   中英

What is the right way to write a bash script for cron job

I have written a bash script that is supposed to be executed by a cron job. But according to the cron output one of the lines in the bash script is not executing.

Here is my bash script

#! /bin/bash
/usr/bin/mysql</home/elijah/Desktop/covid-19-management-tool/cron_job/import.sql
./home/elijah/Desktop/covid-19-management-tool/cron_job/clear

This is the output I got from cron after execution

X-Cron-Env: <HOME=/root>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=root>
Message-Id: <20210205172001.F3C5FE221D@elijah-HP-255-G6-Notebook-PC>
Date: Fri,  5 Feb 2021 20:20:01 +0300 (EAT)

/home/elijah/Desktop/covid-19-management-tool/cron_job/dbs.sh: line 3: ./home/elijah/Desktop/covid-19-management-tool/cron_job/clear: No such file or directory

--F3C5FE221D.1612545602/elijah-HP-255-G6-Notebook-PC--

For line 3 in my bash script I want to run an executable called clear .

Someone please tell me how I should do it in the shell script so that cron can understand it.

Get rid of the . before /home (unless you have indeed the following directory structure):

/home/elijah/home/elijah/Desktop/covid-19-management-tool/cron_job/clear

The . makes this a relative path, while it's most likely meant to be absolute.

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