Home > Net >  How to run cronjob in azure cloud bash shell
How to run cronjob in azure cloud bash shell

Time:12-15

I'm trying to run cron job in azure cloud shell but it is not working

This is my simple cron job

* * * * *  /home/meet/clouddrive/temp.sh

where

cat /home/meet/clouddrive/temp.sh
#!/bin/bash
echo "meet" >> /home/meet/clouddrive/test.txt
pwd
/home/meet/clouddrive
meet [ ~/clouddrive ]$ ls
temp.sh

CodePudding user response:

The script is located at /home/meet/clouddrive/temp.sh. However, the pwd command in the script outputs /home/meet/clouddrive, which suggests that the script is not in the current working directory. To fix this, you can either adjust the path to the script in the cron job, or you can change the current working directory in the script to the correct location.

Make sure that the script has the appropriate permissions to be executed. You can check the permissions for the script using the ls -l command, and you can change the permissions using the chmod command. For example, to make the script executable by the owner, you can run chmod u x /home/meet/clouddrive/temp.sh.

Can you try running the script manually from the command line to see if it works fine?

CodePudding user response:

I tried to reproduce the same in my environment and got the results like below:

I tried to run Cron job in azure cloud shell like below:

when I try crontab -l there is no job from here.

enter image description here

Then create crontab -e

Run */1 * * * * echo "this is a test" /home/imran123/testfile.txt

Then try to create a file using vi testfile.txt and I mention "This is test"

Then try to give execute permission like below:

chmod x test.sh

enter image description here

Then when I executed cmd it run successfully like below:

crontab -l
cat testfile.txt

enter image description here

  • Related