运行的crontab与用户输入 [英] Run crontab with user input

查看:423
本文介绍了运行的crontab与用户输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了将运行bash脚本test.sh.一个crontab此test.sh文件需要来自用户的某些输入,并保存用户输入的变量。我如何确保用户输入将以test.sh保存到一个变量,当crontab中运行该脚本,我可以得到我想要的输出?

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?

对于例如我有2个文件,file1.sh和file2.sh。我把file2.sh文件1.sh.我然后运行file1.sh,得到了用户的输入,并保存在某个地方。 crontab中运行file2.sh,并从提取值的保存某处变量的。反正是有这个?

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?

推荐答案

如果输入的是由脚本标准输入读,只是重定向从文件输入(使用包装脚本)。

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

如果这不会为你工作(即你有你的脚本中调用telnet等一些交互shell程序,你可以使用 期待 自动进行互动。

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.

这篇关于运行的crontab与用户输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆