The idea is to have a interactive script to delete directory under /home/user/ area from all the remote servers via ssh .. I have created list of server in /tmp/list to call the same in for loop. The problem is that the script does not work interactively and completes the entire loop for all servers without taking any options. Please provide your valuable inputs
Thanks
Kpatel.
Moderator's Comments:
Please wrap all code, files, input & output/errors in CODE tags.
It makes it far easier to read and preserves spaces for indenting or fixed width data
Last edited by rbatte1; 07-19-2016 at 09:37 AM..
Reason: Added CODE tags
The set -x line will negate the 'shebang' line which forces the code to run under ksh. You may get away with it if you are running ksh as your shell already.
Some indenting you make it much clearer.
Wraping your code with [CODE] & [/CODE] tags will make it far easier to read and preserve the spacing for indenting or fixed width data.
You have what is known as a UUOC for your loop. I have a better way shown in green
The variable i is not very descriptive. Usually better to have a sensible name for variables so you can read your code as a natural language.
You use ll -ld where ll is an alias, often to ls -l but this output would surely never match what is being keyed in.
You prompt and read as two commands. There is a ksh way to do this in one shown in blue.
With indenting and the other adjustments, I get your code to be:-
I must admit I am confused.
It's an automated process, but you seem to prompt for input. The ssh and the embedded read statements will be gobbling up your input for the file the way you had it, however I'm struggling to work out the purpose overall.
Can you elaborate on the logical you are trying to achieve. I've got:-
For every server in a list (file), connect and:-
Display the OS information
Change to the home directory of user user (if it exists)
Prompt for a directory, then try to match that to the current directory in an odd way
If it matches, delete the current directory whilst still in it (?) after pressing ENTER with no chance to escape.
If it doesn't match, just display a message
Disconnect ungracefully by terminating the input (EOF)
After pressing ENTER, logout! - oh, everything will exit, perhaps closing your window if it's PuTTY or something else set to close on exit.
Sorry, but I'm a bit lost as to the purpose. Can you lay out a description of what you are trying to achieve?
Perhaps the logout should be before the EOF as a starter.
Should this really be an interactive script within the ssh bit?
If you can lay it out, then I'm sure we can help you.
Thanks for your response.. I have 500 odd servers which have some unused user directories , these directories need to be deleted.
I have one server which can be used to connect to all these servers via ssh wihout any password.
The idea is to put the entire server list is file and run a for loop and connect to all those servers do cd to the /home area .. then interactivily ask for the directory to be deleted. Once the input is provided it should delete the directory and then logout from that server to continue the loop for the remaining servers.
@rbatte1: if you replace the for loop with a while read loop, then this takes stdin away from ssh (like ssh was taking stdin away from the read statement from the remote execution script). So in addition to my suggestion in post #2 you need to read the server name from a different file descriptor:
These 2 Users Gave Thanks to Scrutinizer For This Post:
Hi
Wishing to all.
I am very new joined in an organization as a unix system administrator.
I need a help in preparing a script for a report.
i have a file contains all of the linux/ubuntu servers line by line around 140 servers.
vi servers.txt
nh01
nh02
nh03
bh01
bh04
-
-
:wq (3 Replies)
Hi all,
I am baffled on this. Solaris Irix system.:confused:
I have 4 servers all connected to one another, :b: I need to write a script line that would login on to server 1-3 ($HOST) start a script in the back ground and log off while the back ground script runs over a length of time.:eek:
... (10 Replies)
Hi,
I need a script that will connect to a list of servers and first sudo to root and then run a couple of commands.
For security reasons, we can't setup ssh keys as root.
Manually I have to login to a server as user and then sudo to root.
It's not possible to use root@servername , because of... (8 Replies)
new3=`cat /tmp/list3`
for pol in "$new3" $(su - dbadmin -c "ssh $new3 '/usr//llist'");
do export policy=`echo $pol`; su - dbadmin -c "ssh $x '/usr/policycmd $policy -L |grep -i active; echo $policy'">>/tmp/listxyz;done
I am having trouble with this testscript as the file list3 has two names... (1 Reply)
I need a shell script using expect to login to couple of remote servers and read "crontab -l -u <username>" & "cat /etc/rc.local" & "df -h" and able to create output into a file saved locally with hostname.crontab & hostname.rc.local & disk.status. I can supply a file as list of hostname or IP... (4 Replies)
So I have a scriptlet called solaris_command:
for i in \
server1 server2 server3
do
echo $i
ssh $i $1
echo ""
done
I then use that as a command in multiple scripts to allow for data gathering for all virtual hosts in the environment thusly:
solaris_command "cat... (3 Replies)
Hi, I'm new to C Shell programming. I'm trying to check if a sym link exists on remote server if not send email. I'm not having much luck. Can anyone help?
Here is what I have written but it doesn't work. It tells me that my variable was not defined. Here is part of the script, the second... (0 Replies)
Hi,
I am running a shell script from a central server to multiple remote servers using the following code:
application_check()
{
# Linux/UNIX box with ssh key based login
SERVERS=`cat /tmp/server-details`
# SSH User name
USR="user"
# create new file
> /tmp/abc.log
# connect... (2 Replies)
Experts,
Im trying to remote into a server, run a script that resides on that server and capture the information displayed & store in a local file.
I struggled with this yesterday & finally that script is working now.
Now, here is a scope creep and the script that I wrote for 1 remote... (2 Replies)
All, I need to write an unix shell script which inserts some records into a file located in remote servers.
* Get the input from the user and insert according the first row. It should be in ascending order.
123451,XA,ABA
123452,XB,ABB
123453,XC,ABC
123455,XE,ABE
123456,XF,ABF
123458,XG,ABG... (2 Replies)