简体   繁体   English

为了自动化,在Bash / KSH中自动将值传递给脚本菜单

[英]Automatically pass a value to a script menu for automation's sake in Bash/KSH

Trying to make a small script and cron job it in order to automate a task. 尝试制作一个小的脚本并进行cron作业以自动化任务。 Said script runs another script which has already been created, grabs the output, emails to specified recipients, and cleans up the output. 所述脚本运行另一个已经创建的脚本,获取输出,通过电子邮件发送给指定的收件人,并清理输出。 I've got it almost down however am running into one major issue. 我几乎将它记下来了,但是却遇到了一个重大问题。 The script that mine is running has a menu on the outset. 我正在运行的脚本在开始时就有一个菜单。 That is to say, running the script by itself manually, i would have to select option 1 in order to get the output i want (the only other option, 2, is quit.) 也就是说,手动运行脚本本身,我必须选择选项1才能获得所需的输出(退出的唯一其他选项2)。

How can I automatically enter (or simulate entering) the value 1 into the other script, so it does not hang when in a cron job waiting for user input? 如何自动将值1输入(或模拟输入)到其他脚本中,以便在执行cron作业等待用户输入时不会挂起?

Is there a sane way to do this? 有理智的方法吗?

Thanks in Advance. 提前致谢。

You could try something as simple as using yes | command 您可以尝试使用yes | command一样简单的方法yes | command yes | command if answering yes is all that is needed. 如果只需要回答是,则yes | command Otherwise you probably want to use expect to drive the imaginary keyboard for you. 否则,您可能想使用Expect为您驱动虚拟键盘。

http://expect.sourceforge.net/ http://expect.sourceforge.net/

Using autoexpect to record your session is a convenient way to come up with rough draft expect scripts as well. 使用autoexpect记录会话也是一种方便的方法,可以提出粗略的期望草稿脚本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM