Solved

Linux,scripting with ssh and sshpass

Posted on 2013-12-19
2
598 Views
Last Modified: 2013-12-20
I can get the ssh command to remotely perform file with commands such as ls -la, etc, but I am having difficulty in some other areas:

I have two scenarios, one works, the other does not:

WORKING SCENARIO

I have 2 ssh session running and do the following:

First session:

I start an ftp session

[root@xxclnt1 etc]# ftp
ftp>

Open in new window



The second session

I kill the ftp session

[root@xxclnt1 home]# cat test.sh
pkill -9 ftp

[root@xxclnt1 home]# ./test.sh
[root@xxclnt1 home]#

The first session then successfully terminates the FTP

[root@xxclnt1 etc]# ftp
ftp> Killed
[root@xxclnt1 etc]#


NON_WORKING SCENARIO

The first session starts ftp as before

[root@xxclnt1 etc]# ftp
ftp> Killed

Open in new window


The second session then calls ssh to perform the test.sh (on the same machine as the caller, trying
to understand how this works so I can write more meaningful scripts involving terminating remote clients)

sshpass -p 'xxxxx' ssh root@xxclnt1 /home/test.sh

Open in new window



However, the ftp is still alive in the other session, and can also been see with the ps command

[root@xxclnt1 home]# ps -ef | grep ftp
root      6471  6046  0 14:19 pts/1    00:00:00 ftp
root      6491  6445  0 14:21 pts/2    00:00:00 grep ftp
[root@xxclnt1 home]#

Open in new window


1> Most importantly, why did the test.sh fail to work

2> and how can I get it to work ?

Thanks
0
Comment
Question by:Los Angeles1
2 Comments
 
LVL 40

Accepted Solution

by:
omarfarid earned 500 total points
ID: 39730155
Can you describe your requirement? please elaborate more
0
 

Author Comment

by:Los Angeles1
ID: 39730177
Basically I am learning scripting, and I eventually hope to remotely kill running clients on the remote machines using ssh

So I am starting with ftp as a client I am attempting to kill, and will work up to the more robust industry standard clients as I go
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Delete email that have a topic like  Cpanel 3 69
Java / Linux and Regular Expressions 11 69
Anti-virus for Linux Server 15 124
Can't See Site After DNS Resolved 7 47
In this tutorial I will explain how to make squid prevent malwares in five easy steps: Squid is a caching proxy for the Web supporting HTTP, HTTPS, FTP, and more. It reduces bandwidth and improves response times by caching and reusing frequently-…
I am a long time windows user and for me it is normal to have spaces in directory and file names. Changing to Linux I found myself frustrated when I moved my windows data over to my new Linux computer. The problem occurs when at the command line.…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now