简体   繁体   English

从前端的另一个Shell脚本调用Shell脚本

[英]call shell script from another shell script in front end

i created one script space.sh on one server and this script do ssh on other servers and check mount point. 我在一台服务器上创建了一个脚本space.sh ,此脚本在其他服务器上执行ssh并检查安装点。 if password of any server is not working or expired it will simply print out server name or ip and will ask for password. 如果任何服务器的密码不起作用或已过期,它将仅打印出服务器名称或ip并询问密码。

i want output on my mail. 我想在我的邮件上输出。 So for this i created one more script mail.sh . 为此,我又创建了一个脚本mail.sh and simply called sh space.sh >> test.txt and with mailx getting this on my mail. 并简单地称为sh space.sh >> test.txt并通过mailx将其保存在我的邮件中。

And here problem comes. 问题来了。 while running mail.sh it is not asking for password because space.sh is now running in backend. 在运行mail.sh时,它不需要输入密码,因为space.sh现在在后端运行。

The problem is, that your script space.sh is waiting for input, while the mailx program you call later is waiting for output. 问题在于,您的脚本space.sh正在等待输入,而您稍后调用的mailx程序正在等待输出。 So you created a deadlock. 因此,您创建了一个死锁。

Scripts that are supposed to run non-interactively should not ask for user input. 应该以非交互方式运行的脚本不应要求用户输入。

I would advise to use public keys for the login and call ssh in a way it does not wait for input, ie does not use passwords, for example like this: 我建议使用公用密钥登录并以不等待输入的方式调用ssh,即不使用密码,例如:

ssh -o "PubkeyAuthentication=yes" -o "PasswordAuthentication=no" hostname

If the login is not possible because of missing keys, this does not try PasswordAuthentication, but returns with an error: "Permission denied (publickey,password)." 如果由于缺少密钥而无法登录,则不会尝试PasswordAuthentication,而是返回错误:“权限被拒绝(公共密钥,密码)。”

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

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