Login or Register to Ask a Question and Join Our Community


ssh command headache


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users ssh command headache
# 1  
Old 03-05-2009
ssh command headache

Good day,

I am trying to run a ssh command on a remote server, but when I run the command the server takes FOREVER... and ends up giving me an error..
then the script also kicks server load up by 100% while it is running..
But if I run the same command on the server it goes pretty quickly and gives the correct std output.

Command on server:
readonly@VCRE02 ~# YEAR=2009;DAY=27;MONTH=02;LMONTH=Feb;for t in 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23; \
do nice -n 20 gunzip -c "/log-archive/access.log_$YEAR$MONTH$DAY_"*$t.gz |nice -n 20 nawk -v a=$t '{total[$8] += 1} END{for (i in total) print a,i, total[i]}' ;done
<std output below>
00 "200" 353061
00 "302" 5001
00 "404" 3689
00 "304" 20030
00 "500" 592
(this of course is what I want..)

ssh command:
Servername=cre02 ; ServerIP=10.113.98.17 ;nice -n 20 ssh readonly@$ServerIP 'YEAR=2009;DAY=27;MONTH=02;LMONTH=Feb;for t in 00 01 02 03 04 05 \
06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23; do nice -n 20 gunzip -c "/log-archive/access.log_$YEAR$MONTH$DAY_"*$t.gz | \
nice -n 20 nawk -v a=$t '\''{total[$8] += 1} END{for (i in total) print a,i, total[i]}'\'' ;done'
<std error below>
gunzip: /log-archive/apache/access.log_200902*00.gz: No such file or directory
gunzip: /log-archive/apache/access.log_200902*01.gz: No such file or directory
gunzip: /log-archive/apache/access.log_200902*02.gz: No such file or directory
gunzip: /log-archive/apache/access.log_200902*03.gz: No such file or directory
gunzip: /log-archive/apache/access.log_200902*04.gz: No such file or directory
(this is not what I want)

I have tried quoting the filename for the "gunzip -c" command in various ways, but is does not really work.
ex. gunzip -c "/log-archive/access.log_$YEAR$MONTH$DAY_"*$t.gz
gunzip -c /log-archive/access.log_$YEAR$MONTH$DAY_*$t.gz
gunzip -c /log-archive/access.log_$YEAR$MONTH$DAY*$t.gz
no luck.

This is a sample filename of the files I am trying to gunzip:
/log-archive/access.log_20090101_00.gz

I noticed if I "cat" the files that have not yet been archived the whole process goes much smoother and there is no issues with the filenames..

So somewhere I am doing something wrong.. and for the life of me I cannot figure out what it is.

Any advise on this will be greatly appreciated.

Thanks.
# 2  
Old 03-05-2009
I think you're running afoul of ' characters forcing * to be literal in your ssh command. Plus nice on your side does not mean it got niced over there.

You've got keys, right?
So we write a small script on your end using what works, you may want to make it use 4 parms instead of YEAR=xxxx, etc.
Code:
# script.sh
YEAR=2009
DAY=27
MONTH=02
LMONTH=Feb
for t in 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 
do 
  nice -n 20 gunzip -c "/log-archive/access.log_$YEAR$MONTH$DAY_"*$t.gz |
  nice -n 20 nawk -v a=$t '{total[$8] += 1} END{for (i in total) print a,i, total[i]}' 
done

next we write a tiny script that stays on your side:
Code:
# tiny.sh
sftp readonly@server1 << EOF
put script.sh
exit
EOF
ssh readonly@SERVER01 chmod +x ./script.sh && ./script.sh > output

You execute tiny.sh from home.
# 3  
Old 03-06-2009
Thanks for the reply Jim.

The nice command does work very..um.. nicely..
The problem I have is that I am not allowed to place any files on the servers I have to monitor. I am sitting in development environment, they are all on production and I do not have enough privileges to do anything on production.
That is why I have the whole "string-of-infinite-headache" following the ssh command..

So what can I do without slapping files on the server itself?

This command for example works 100% (with dates substituted of course)
ssh readonly@$ServerIP 'YEAR=xx;DAY=xx;MONTH=xx;LMONTH=xx;for i in 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 \
16 17 18 19 20 21 22 23; do cat "/var/SP/log/cre/access.log_$YEAR$MONTH$DAY_"*$i | grep -c "HTTP/1.1\" \"500";done'

Last edited by msullivan; 03-06-2009 at 02:12 AM..
# 4  
Old 03-06-2009
I figured it out! Smilie Just had to change the stupid quotes...

Now the script goes helluva fast and only uses around 0.6-0.8% Utilization, compared to 14% if the gunzip filename does not match properly...

ssh_function_CRE()
{
ssh readonly@$ServerIP 'YEAR=2009;DAY=28;MONTH=02;LMONTH=Mar;for t in 00 01 02 03 04 05 06 07 08 09 10 11 \
12 13 14 15 16 17 18 19 20 21 22 23; \
do nice -n 20 gunzip -c /log-archive/access.log_$YEAR$MONTH$DAY"_$t".gz |\
nice -n 20 nawk -v a=$t '\''{total[$8] += 1} END{for (i in total) print a,i, total[i]}'\'' ;done'
#echo "$Servername, $Date" > $EFCRE
sleep 1 ; cat $sshEF >> $EFCRE
}
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Execute ssh command with additional terminal command to any remote user not working script

Hello i am having an issue with bash script and this is the code now=$(cat hosts1.txt | awk '{print $2;}') while read n ;do ssh root@$now 'useradd test1; echo -e "test1\ntest1" | passwd test1 && echo "test1 ALL=(ALL:ALL) ALL" >> /etc/sudoers' When i execute only part with cat, it... (8 Replies)
Discussion started by: tomislav91
8 Replies

2. Shell Programming and Scripting

Beginner: script headache

Hi, I am new to shell scripting, but doing my best to learn things. Today doing courses there was exercise like this: #!/usr/bin/bash a=$1 b=$2 if ] then echo "Conditions are met" else echo "Conditions are not met" fi I improved it a little, beacuse of curiosity :D to this: ... (8 Replies)
Discussion started by: Rosentine
8 Replies

3. UNIX for Dummies Questions & Answers

formatting a file headache

Hello does anyone know how to do the following using some simple unix if possible: I have a file with the following info as comma separated. It shows username, id number and all the subjects they are enrolled in on the one line. The subjects are separated by colons. UserName,ID,Subject... (13 Replies)
Discussion started by: ynneycat
13 Replies

4. Shell Programming and Scripting

Friday afternoon headache

Hi all, It's been a long week and my brain is clearly not functioning right so hopefully someone can help me out here. I've got a function in a script which just checks if a MySQL database directory exists or not. Code is as follows: dbCheck2() { if ; then { : # carry... (4 Replies)
Discussion started by: _Spare_Ribs_
4 Replies

5. Shell Programming and Scripting

scripting headache... loops & variables

Surely there's an easier way to do this, lets see if anyone knows! I am new to scripting so go easy on me! I have the following script and at the moment it doesn't work and I believe the problem is that I am using a while loop within a while loop. When I run the script using sh -x I can see... (6 Replies)
Discussion started by: StevePace
6 Replies

6. UNIX for Dummies Questions & Answers

sed headache

Hi all, I've got a thorny sed/regex problem and I thought somebody out there might be able to help. I'd like to use sed in a Makefile to parse a path string. The path might look like this: case 1: /mnt/users/bob/build/src or case 2: /mnt/users/bob/build/src/foo or case 3: ... (4 Replies)
Discussion started by: gnarl
4 Replies

7. Shell Programming and Scripting

sed make me headache... need help!

I've still a little problem with sed. So, the content of my file.txt is like: 101.10.20.2.1079 > 101.11.2.20.80: 101.10.20.2.1080 > 101.11.2.20.80: 101.10.20.2.1081 > 101.10.20.2..80: 101.05.15.143.1068 > tpo68-96-22-1.no.no.cox.net.4391: 101.05.15.143.1072 >... (5 Replies)
Discussion started by: nymus7
5 Replies

8. Solaris

A very headache problem

guys, need your help~~~~ I am setting up a Sun Enterprise 450 Ultra 4 server originally I was using Sun solaris 9 1202 version. but after an accident (i guess becoz i deleted something wrongly), the system cannot boot up. and now I wana install a FreeBSD(since it is free and it will... (3 Replies)
Discussion started by: MrDJay
3 Replies

9. IP Networking

DHCP client & ipchains headache

Hi all, I upgraded my SUSE 6.1 to SUSE 7.1 and at once the following things won't work anymore: 1) My DHCP client is not able anymore to retrieve my IP address from the @home server. It times out all the time. If I use a fixed IP I can get on the net, so there is no physical problem. 2) I... (3 Replies)
Discussion started by: Micky
3 Replies

10. UNIX for Dummies Questions & Answers

extremely headache

I need to execute command at remote host from my program. there is rs6000/aix standard command called rexec. unfortunately rexec ask username and password which must supplied interactively, of course it is impossible runned by program. So I have to change rexec command format to make user-name... (5 Replies)
Discussion started by: yatno
5 Replies
Login or Register to Ask a Question

Featured Tech Videos