I have a run a script in cronjob. But that script is taking some user input.
How can I handle such case?
If it's taking the input from stdin, make another script that will call your script with a pipe or a redirect.
#!/bin/sh
/foo/bar/my_command < my_input
You can also launch it as a shell command in your crontab:
0 * * * * /bin/sh -c "/foo/bar/my_command < my_input"
Modify the script so it does not need user input.
Feed the script its required input from a file, via <
.
Just in case the "expected user input" is, by any chance, a password: Do not use option 2. Editing access authentification into a crontab job is various flavors of dangerous.
PS: That warning above is also true if you're thinking about expect
, as suggested by mvp. It is basically the equivalent of writing down your password on a post-it and sticking it to your monitor: Easy, convenient, and not secure at all.
如果您只需要在脚本中确认(是),crontab 可能如下所示:
0 * * * * /bin/sh -c "yes | /foo/bar/my_command"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.