Abhay Nayak
Abhay Nayak

Reputation: 1109

Running shell script as a cron on Ubuntu

I've written a simple script date.sh in /home/user/test

date -u > file.txt

This should write the current date and time in file.txt. I've given it the necessary access right with chmod +x date.sh. When I run the script from the terminal it works fine and updates the time in the text file.

But when I run it as a cron

* * * * * /bin/sh /home/user/test/date.sh

I don't see the dates changing in file.txt As my knowledge about this is limited at the time, my question is, how can I run the date.sh script as a cronjob

Upvotes: 0

Views: 162

Answers (2)

Abhay Nayak
Abhay Nayak

Reputation: 1109

The problem is with date.sh, it should NOT be date > file.txt All the files should contain their entire path. In this case the script should be

date > /home/user/test/file.txt

Upvotes: 0

JESLIN JOY
JESLIN JOY

Reputation: 51

Try providing a full output file path in the script.

#!/bin/sh
date -u > /home/user/test/file.txt

Upvotes: 1

Related Questions