reduce ssh calls / cleanup


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting reduce ssh calls / cleanup
# 8  
Old 09-09-2011
i was able to get things working properly.. my issue ended up being more with the SSH and sudo interactions and when i needed to use the -t and when i needed to use -Tt.. For some commands, i had to pull them out and move them into their own ssh connection (ie passwd)
In looking at your suggestions, i also was able to get rid of a lot of unneeded testing that i was doing in my script.
I think i have been able to clean up at least 100 lines of unneeded code with your pointer..

so just wanted to say thx!

---------- Post updated at 03:12 PM ---------- Previous update was at 02:57 PM ----------

1 last quick question.. as part of one of my scripts, i am creating the user account.. How do i need to surround the $5 in the bottom code box below in order for it to display the whole comment field? Previously, when using all my numerous ssh calls, i had been using
Code:
ssh -t $USER@$SERVER $ADMINCMD /usr/sbin/useradd -u $UIDNUM -g 111 -G 14 -s /bin/ksh -c "'$COMMENT'" $USERNAME

Currently as it sits below, for a comment field that contains "test user" i am only getting test as the comment.. i have tried numerous variations of ", and ' with no luck

Code:
ssh -qTt $USER@$SERVER /bin/bash -s "$USERNAME" "$ADMINCMD" "$OSVER" "$UIDNUM" "$COMMENT" >> /tmp/passwdlist <<"EOF"
case "$3" in
5.10 ) # Create the Solaris 10 account with the user in the Primary Admin profile
if ! "$2" /usr/sbin/useradd -u "$4" -g 111 -G 14 -s /bin/ksh -c ""$5"" -P "Primary Administrator" "$1" > /dev/n
ull
then
echo "`hostname`|Couldn't create user account"
exit 1
fi
# Verify account has been created by checking /etc/passwd
if grep -w "$1" /etc/passwd > /dev/null
then
echo "`hostname`|User account created"
exit 1
fi
;;
* ) # Create the account
if ! "$2" /usr/sbin/useradd -u "$4" -g 111 -G 14 -s /bin/ksh -M -c ""$5"" "$1" > /dev/null
then
echo "`hostname`|Couldn't create user account"
exit 1
fi
# If OSVER is greater than 5, assume a linux kernel and put user in wheel and users group
case "$3" in
2.* ) "$2" /usr/sbin/usermod -G 10,100 "$1"
;;
esac
# Verify account has been created by checking /etc/passwd
if grep -w "$1" /etc/passwd > /dev/null
then
echo "`hostname`|User account created"
exit 1
fi
;;
esac
EOF

# 9  
Old 09-09-2011
When you ssh, one layer of quotes gets stripped out. ssh username@host echo "stuff in quotes" becomes echo stuff in quotes. You have to add in literal quote characters to preserve quotes.

Code:
ssh username@server echo "\'stuff in quotes\'"

# 10  
Old 09-12-2011
hmmm.. i'm still having issues with that last piece.. could you show me what i am doing wrong in this code? The issue is with the $5 part of the useradd command.. (i added some echo tests at the top to try to help figure out the errors of my ways, and snipped out some case statements for berevity)

Code:
ssh -qTt $USER@$SERVER /bin/bash -s "$USERNAME" "$ADMINCMD" "$OSVER" "$UIDNUM" "\'$COMMENT\'" "$LAWSON" "$ROLENAME" "$EXPIRY" "$SERVER" >> /tmp/passwdlist <<"EOF"
case $9 in
* ) echo "\'$5\'" > /tmp/testuser; echo \'$5\' >> /tmp/testuser; echo "'$5'" >> /tmp/testuser
    if ! "$2" /usr/sbin/useradd -u "$4" -s /bin/ksh -c "$5" -d /home/"$1" "$1" > /dev/null
    then    
        echo "`hostname`|Couldn't create user account" 
            #exit 1
    else
        echo "`hostname`|User account created" 
            #exit 1
    fi
    # if expiration is not empty, set on account
    if [ ! -z "$8" ]; then
        "$2" /usr/sbin/usermod -e "$8" "$1"
    fi
    # if user needs to be added to a role, set it here
    if [ ! "$7" = "exclude" ] && [ ! "$7" = "dontexclude" ]; then
        "$2" /usr/sbin/usermod -R "$7" "$1"
    fi
    ;;
esac

i had added the echo testers and as it sits when using a comment field containing "test user", my current output in /tmp/testuser is
Code:
\''test\'
''test'
''test'

and below is how the script for this particular command looks when running it with set -x
Code:
+ ssh -qTt user@dellpoc1 /bin/bash -s tester2 /usr/bin/sudo 2.6.18-194.32.1.el5 3033 '\'\''test user\'\''' false dontexclude 12/12/2012 dellpoc1

thanks again! you have been extremely helpful!
# 11  
Old 09-12-2011
I think you've mistaken some double quotes for single quotes.

The inner quotes can be single, but the outer probably should be double -- escaping doesn't even make sense in single quotes.

You don't even need to escape single quotes inside double-quotes, which makes them convenient too.

Code:
"'test user'"

---------- Post updated at 08:40 AM ---------- Previous update was at 08:39 AM ----------

When in doubt, you can always just echo a string to see how it'll end up on the other end:

Code:
$ echo "'test user'"
'test user'

Much faster than rerunning the whole thing every time Smilie
This User Gave Thanks to Corona688 For This Post:
# 12  
Old 09-12-2011
doh! i was looking at the wrong side of things..

set it to "'$COMMENT'" and things are working great...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

UNIX script for cleanup

Hello, I need some help from unix guru's here..I am looking for some advanced level script to cleanup the directories and files from specific directories under a file system.. The folders are created under /opt/modules And under modules, there are multiple subfolders with the application... (6 Replies)
Discussion started by: mb525
6 Replies

2. Red Hat

How to Cleanup Multipathing

I have a server running redhat 5.5 and it has one SAN device presented to it as LUN9. How can I clean up the remaining entries. I cannot afford to interupt the service. Please assist. # multipath -l mpath0 (36000097000019260298953666633436) dm-11 EMC,SYMMETRIX \_ round-robin 0 \_ 2:0:0:9 ... (2 Replies)
Discussion started by: Tirmazi
2 Replies

3. UNIX for Advanced & Expert Users

Table Cleanup Script

I needed some help with a script to fetch and delete all records prior to 3 days from now connecting to sybase from sunos. I wrote the following script but not working..can someone please guide me with my code. Thanks #!/bin/ksh ##GET PREVIOUS DAY DATE dt=`date | awk... (3 Replies)
Discussion started by: moe458
3 Replies

4. Shell Programming and Scripting

Cleanup between parenthesis

Hi, I am trying to clean up data between parenthesis () in a file. See example below.... Input File : (New York) Chicago (London) New York (Chicago) London New York Chicago (London) (New York) (Chicago) (London) New York (Chicago) ... (3 Replies)
Discussion started by: msalam65
3 Replies

5. Solaris

/home cleanup

Hi All, I have this script for linux on cleaning up orphaned folder. But I need to use this on solaris 8/9/10 for user in $(ls | grep -v lost+found) ; do id $user >/dev/null 2>&1 if ] then ls -ld $user grep $user /etc/passwd fi done Can someone please convert this script? ... (1 Reply)
Discussion started by: itik
1 Replies

6. Shell Programming and Scripting

Cleanup script

Hi! I would like to write a script which remove some files, all beginning with the same prefix : prefix.1 doc/prefix.2 ../prefix.3 etc. So, I would create a file and chmod it executable. But I dont know how to pass a variable to a script. I would like to write something like ... (2 Replies)
Discussion started by: tipi
2 Replies

7. Shell Programming and Scripting

Help with cleanup

I am trying to add a unique string to a variable to prevent some name space collisions. DATAFILE=/u001/app/unica/affinium644/campaign/partitions/limited/tmp/ebf9aaah.t~# DATETIME=`date +%Y%m%d_%H%M%S` echo $DATAFILE > tmpnme.txt sed 's_/_ _g' tmpnme.txt > tmpnme2.txt DATA=$(cat tmpnme2.txt)... (2 Replies)
Discussion started by: whdr02
2 Replies

8. IP Networking

Identification of data calls & voice calls

Is there any facility to filter/identify the data calls and voice calls coming throug modem? OR Can we get the data or voice calls information through a script(preferably C Kermit)? (0 Replies)
Discussion started by: pcsaji
0 Replies

9. AIX

Login ID cleanup

Hello I have many old IDs on my AIX and would like to know the simplest way of knowing the last time an ID was used. I am familiar with the "last" command. Thanks for any info :) (1 Reply)
Discussion started by: MILLERJ62
1 Replies

10. UNIX for Dummies Questions & Answers

sendmail cleanup

What is the correct procedures to clean up /var/spool/mqueue? Any help appreciated. This directory gets really clogged up at times. :( :( (1 Reply)
Discussion started by: thomi39
1 Replies
Login or Register to Ask a Question