Execute Shell script via Plink


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Execute Shell script via Plink
# 1  
Old 08-08-2014
Execute Shell script via Plink

I am trying to create a bat file with the below piece of code.
Code:
plink.exe -l username -pw password -P 22 -2 -ssh servername
sudo su - devuser
cd /opt/sample
echo 3 | ./Script.sh

It executes only the first line and not the rest of the lines.
Can you please help me where am I doing wrong?
# 2  
Old 08-08-2014
You haven't fed that code into plink, therefore it's not being fed into plink.

CPM-style commandline doesn't have many effective redirection methods, so this is much harder in CMD than it would be in shell. It would be far better to save the commands you want in an external file so you could do:

Code:
plink.exe -l username -pw password -P 22 -2 -ssh servername -batch -m commands.txt

# 3  
Old 08-08-2014
"Sorry, user is not allowed to execute '/bin/su ΓÇô devuser' as root on
servername."
The above is the error that I get.
Basically my user does not have access to execute the script on the folder that I mentioned.
Does it mean that the sudo didnt implement at all?

---------- Post updated at 01:19 PM ---------- Previous update was at 12:55 PM ----------

The below is the piece of code I had in command.txt
Code:
sudo su - devuser
cd /opt/sample
echo 3 .Script.sh

# 4  
Old 08-08-2014
Much like plink -- or any other command -- if you don't feed commands into su, they don't get fed into su. It doesn't just "take over" the script you're running.

Fortunately, it's a lot easier to feed things into a program in UNIX sh than in CPM.

Code:
sudo su – devuser <<EOF
cd /opt/sample
echo 3 .Script.sh
EOF

# 5  
Old 08-09-2014
The problem is I have 100+ servers where I need to run the desired shell script.
It is a himalayan task to have the script modified with the few more lines of script.

I tried the below code in commands.txt file.
Code:
sudo su – devuser <<EOF 
cd /opt/sample 
echo 3 ./Script.sh 
EOF

I got the below response.
"[sudo] password for username:"
Even if I enter the password it is displaying the below error.
Code:
Sorry, user username is not allowed to execute '/bin/su û devuser' as root on server

I know that username doesn't have the persmission to execute the script in the desired folder.
I am thinking that still sudo is not executed properly.
# 6  
Old 08-11-2014
Why not login as devuser in the first place, instead of ssh-ing into the wrong user? Then you'd be logged in as the right user with the right password and not have to deal with any cramming-a-bruteforced-password-into-su nonsense -- which is even more difficult than it sounds, because a UNIX password prompt is designed to prevent passwords being typed into it automatically. 'interactive password authentication' means 'password typed by a human being in realtime' authentication and no program pretending to be a human is acceptable...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Batch script to execute shell script in UNIX server

Hi team, My requirement is to transfer pdf files from windows machine to unix server and then from that unix server we should sftp to another server. I have completed the first part i.e From windows to using to unix server with the help of psftp.exe code: psftp user@host -pw password <... (1 Reply)
Discussion started by: bhupeshchavan
1 Replies

2. Shell Programming and Scripting

Execute shell script without using sh

Hi Experts, I want to execute shell script(on HP-UX) wihout specifying interpreter. For e.g generally we use following command to execute shell sh test.sh but I want to execute it as test.sh currently if I execute directly it as test.sh it is giving error Commnd Not... (7 Replies)
Discussion started by: sai_2507
7 Replies

3. Shell Programming and Scripting

Dos batch script to execute unix shell script

Can anyone help me with a dos batch script to execute a shell script residing in an unix server. I am not able to use ssh. Thanks in advance (2 Replies)
Discussion started by: Shri123
2 Replies

4. UNIX for Dummies Questions & Answers

can't execute a shell script

Hi all, As i want to know how the shell command "nohup" worked.I logged in as the user named vincent through Gnome.Then i press ctrl+atl+F1 changed into a console and logged in as another user named kinsley.The user "kinsley" is added by me with "useradd",and now there's no HOME directory for... (6 Replies)
Discussion started by: homeboy
6 Replies

5. Shell Programming and Scripting

How to use ssh execute other shell script on other host (shell script include nohup)?

i want use ssh on the host01 to execute autoexec.sh on the host02 like following : host01> ssh host02 autoexec.sh autoexec.sh include nohup command like follwing : nohup /home/jack/deletedata.sh & after i execute ssh host02 autoexec.sh one the host01. i can't found deletedata.sh... (1 Reply)
Discussion started by: orablue
1 Replies

6. Shell Programming and Scripting

Execute unix shell script to text file using the script

Hi all, I am beginner in UNIX...I want to use unix shell script to create text.file...I know how to use using by command...can anybody tell me for the script? Thanks i changed the threads title from "tex file" to "text file", because "tex" would probably be misunderstood as reference to... (4 Replies)
Discussion started by: mastercar
4 Replies

7. Shell Programming and Scripting

not able to execute shell script

HI, bash-2.05# more mysqlstoporaclestart.sh #!/bin/sh mysqladmin -u root -pengineer shutdown su - oracle -c "bash /export/home/oracle/oracle.sh" bash-2.05# more /export/home/oracle/oracle.sh /oracle/bin/sqlplus "/as sysdba"<< EOF startup nomount... (2 Replies)
Discussion started by: prakash.gr
2 Replies

8. Shell Programming and Scripting

plink and shell script

This is my shell script... test.sh DIRECTORY=/XYZ/PQR if ; then echo "In test.." else echo "lno.." fi when i run this script through a putty its output is: ./test.sh: line 2: [: too many arguments lno.. But when i run the same script using plink its running fine and its... (5 Replies)
Discussion started by: praveen.1
5 Replies

9. UNIX for Dummies Questions & Answers

Execute Shell Script

Hi all, I am begginer of UNIX . I dont know if i have a script written in korn shell with .ksh extention . If i want to execute that how can i do that? Can anybody suggest the best book to learn korn shell scripting. Thanks sam71 (1 Reply)
Discussion started by: sam71
1 Replies

10. Shell Programming and Scripting

How to execute shell Script?

I am new to UNIX , Can any one let me know how to execute shell script (i.e which command I have to use for the same). Any help would be appreciated. Thanks siva mymvs999@yahoo.com (3 Replies)
Discussion started by: siva
3 Replies
Login or Register to Ask a Question