i created a crontab which will run a bash script test.sh. This test.sh file requires some input from the user, and saves the user input into a variable. How do i ensure that the user input will be saved to a variable in test.sh, and when crontab runs the script i can get the output i want?
for e.g i have 2 files, file1.sh and file2.sh. i put file2.sh in file 1.sh. i then run file1.sh, get the user input, and save it somewhere. crontab will run file2.sh, and retrieve the value from the "saved somewhere variable". is there anyway for this?
After the user is done with the crontab, the file is saved in /var/spool/cron/* for each user. Scheduled jobs will be run as the user, with the user's permissions not as root .
* * * * * is a cron schedule expression wildcard, meaning your cron job should run every minute of every hour of every day of every month, each day of the week.
The root user crontabLike any other user, root has a user crontab. Essentially the same as any other user crontab, you are editing the root crontab when you run sudo crontab -e . Jobs scheduled in the root user crontab will be executed as root with all of its privileges.
If the input is read by the script from stdin
, just redirect input from a file (using a wrapper script).
#! /bin/sh
test.sh < data.in
If this does not work for you (i.e. you have your script calling some interactive shell program like telnet, you can use Expect
to automate the interaction.
file1.sh
gets user input and writes it to /etc/file2.dat
file2.sh
reads /etc/file2.dat
and does whatever it needsIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With