Running crontab with user input

i created crontab that will run the bash script test.sh. This test.sh file requires some input from the user and saves the user input into a variable. How can I guarantee that user input will be stored in a variable in test.sh, and when crontab runs the script, can I get the output I want?

for example, I have 2 files, file1.sh and file2.sh. I put file2.sh in file 1.sh. Then run file1.sh, enter user input and save it somewhere. crontab will run file2.sh and extract the value from the "stored variable". anyway for this?

+3
source share
3 answers

If the input is read from the script stdin, just redirect the input from the file (using the script wrapper).

#! /bin/sh
test.sh < data.in

If this does not work for you (i.e. you have a script invoking some kind of interactive shell such as telnet, you can use it Expectto automate the interaction.

+5
source
  • file1.sh receives user input and writes it to /etc/file2.dat
  • file2.shreads /etc/file2.datand does everything he needs
+1
source

. :

, , cron?

, ?

0

Source: https://habr.com/ru/post/1712984/


All Articles