Cron Job prompting for SUDO password

B

brito

Guest
Hi,

I have a simple script that changes a directories permission (from 755 to 777), writes a backup of the database, and then reverts the permission (from 777 to 755). In order to run the chmod commands, I must use sudo.
The issue is we would like to have the script as a cron job, to run automatically, but once it executes, the script prompts for the password and the job fails.

Is there any way to work around this issue?

HTML:
#!/bin/bash
# sample script

sudo chmod 777 /dir1/dir2/backup
sudo su - dbUserName << 'EOF'
echo "Backup Complete"
EOF
sudo chmod 755 /dir1/dir2/backup


Thank you
 


Hi,

I have a simple script that changes a directories permission (from 755 to 777), writes a backup of the database, and then reverts the permission (from 777 to 755). In order to run the chmod commands, I must use sudo.
The issue is we would like to have the script as a cron job, to run automatically, but once it executes, the script prompts for the password and the job fails.

Is there any way to work around this issue?

HTML:
#!/bin/bash
# sample script

sudo chmod 777 /dir1/dir2/backup
sudo su - dbUserName << 'EOF'
echo "Backup Complete"
EOF
sudo chmod 755 /dir1/dir2/backup


Thank you
you need to have the script run as root that way sudo is not needed.
 
you need to have the script run as root that way sudo is not needed.

Would you be able to suggest how to do so? If my script is backupScript.sh for example...

Sorry, I have been trying to find an answer on the web but had no luck so far...
 
To install it in "your" cron file, you would type

crontab -e​

and set things up from there.

To install it in root's cron, you would type

sudo crontab -e​

which will install it in root's cron file. You could also do this:

sudo su -
crontab -e
exit​

to do this as root.

Let us know if you need help setting up cron; there is normally an overview of the fields when you open cron for the first time in the comments section at the top.
 

Members online


Top