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

3

1 Answer 1

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

4
  • 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, 2016 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 ? Feb 11, 2016 at 12:20
  • when i type "sudo -u newUser /folder/" the answer is "sudo: /folder: command not found?
    – Nachtfux
    Feb 11, 2016 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. Feb 11, 2016 at 15:58

Not the answer you're looking for? Browse other questions tagged .