0

I need help for this process. I have a batch file to run Putty and log with ssh an server and will execute commands from file "commands.txt".

C:\Programme\PuTTy\putty.exe -ssh user@server -pw 123456 -m c:\Programme\PuTTy\commands.txt -t

in the command.txt file i will run this commands:

sudo su - newUser
cd /Scriptfolder
./start.sh

My batch runs to switsch user and stopt. The batch switch not in the newUser Folder

Thanks for reply

marked as duplicate by Martin Prikryl, Pimp Juice IT, mdpc, DavidPostill, Ben N Feb 13 '16 at 21:12

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1

If I understood your question, you want to do something like this in command.txt:

sudo su - newUser -c /Scriptfolder/start.sh

or depending on your sudoers config

sudo -u newUser /Scriptfolder/start.sh

  • This dosen´t work... i get the answer: usage: sudo [-D level] -h | -K | -k | -V usage: sudo -v [-AknS] [-D level] [-g groupname|#gid] [-p prompt] [-u user name|#uid] usage: sudo -l[l] [-AknS] [-D level] [-g groupname|#gid] [-p prompt] [-U user name] [-u user name|#uid] [-g groupname|#gid] [command] usage: sudo [-AbEHknPS] [-r role] [-t type] [-C... – Nachtfux Feb 11 '16 at 6:50
  • There was a mistake in "sudo -u newUser -c /Scriptfolder/start.sh", as sudo does not accept "-c". So I edited my answer. I tested the first an second line and both work. The test was realized on CentOS. Which system do you use ? – Ghislain Rouvignac Feb 11 '16 at 12:20
  • when i type "sudo -u newUser /folder/" the answer is "sudo: /folder: command not found? – Nachtfux Feb 11 '16 at 15:31
  • "folder" is a folder. You have to cd in the folder or call your command with full path as in my example. – Ghislain Rouvignac Feb 11 '16 at 15:58

Not the answer you're looking for? Browse other questions tagged or ask your own question.