views:

430

answers:

3

Hi, 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?

+2  A: 

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.

Alex B
+1  A: 

This seems like a strange thing to do. Ask yourself these questions:

Do you really want a popup asking the user for an input value every time the cron runs?

What happens when there's no one at the keyboard?

rix0rrr
what if 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?
Herves
+1  A: 
  1. file1.sh gets user input and writes it to /etc/file2.dat
  2. file2.sh reads /etc/file2.dat and does whatever it needs
scrible