简体   繁体   中英

unable to execute multiple commands in a shell script

I am new to unix and scripting, need your help for the below scenario. These are the contents of my .sh file

#!/bin/bash
usrun xyz
whoami

When I am calling this bash file from putty its asking me for my xyz user's password some other information to properly log in the xyz user. After successfully login, the $ sign in putty changes to #### xyz$, so I am guessing its opening a new session for the xyz user. However, after that, the whoami command is not getting executed. Only after I type exit the whoami command is getting executed.

why is this happening? How to execute the whoami command after successful authentication of xyz user?

The #### represents the last four digits of my server to which I am currently connected to via putty.

The usrun command without any parameters blocks the execution of the bash script. Thus, until the command is not finished (when you type exit), the next command ( whoami ) is not executed.

If you want to login into the machine and execute a command you should try:

#!/bin/bash
usrun -u xyz whoami

The -u option allows you to specify the user and next you can provide the command to execute.

If you want to execute more than one command in the remote machine using Putty I suggest you to follow something similar to this post:

https://superuser.com/questions/1103873/how-to-type-commands-in-putty-by-creating-batch-file

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.

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