2 CMD results on the same line while rexing in a loop


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting 2 CMD results on the same line while rexing in a loop
# 1  
Old 10-02-2009
Bug 2 CMD results on the same line while rexing in a loop

Folks,
I have a 3 problems. In a sh script, I call a server name from a list and rex to a distant machine to get the boot date.

for i in `cat list`
do
(echo "$i|"; /bin/rexsh $i -l bozo -t10 who -b | cut -d" " -f14-16) >>getBootTimes.out
sleep 1
done

The results are on 2 lines instead of 1.
ServerName1_K044|
Jul 10 05:30
ServerName2_K044|
Oct 2
ServerName3_K044|
Jul 19 14:15
ServerName4_K044|
Sep 29 10:22

1. I would like to get the info on the same line
2. with the month & day in a numeric format.
3. Single digit days have to be managed as well

ServerName1_K044|0710
ServerName2_K044|1002 <-note: no "zero" in front of 2 above Oct 2
ServerName3_K044|0719
ServerName4_K044|0929

Thanks for your consideration.
# 2  
Old 10-02-2009
for 1.
Code:
...
do
  (printf "%s|" $i; ...

# 3  
Old 10-02-2009
Quote:
Originally Posted by linux_lou
Folks,
I have a 3 problems. In a sh script, I call a server name from a list and rex to a distant machine to get the boot date.

Code:
for i in `cat list`


There is no need for cat:

Code:
while read i
do
  : whatever
done < list

Quote:
Code:
do
(echo "$i|"; /bin/rexsh $i -l bozo -t10 who -b | cut -d" " -f14-16) >>getBootTimes.out
sleep 1
done

The results are on 2 lines instead of 1.

echo "$i|" prints a newline. Use printf instead:

Code:
printf "%s|" "$i"

# 4  
Old 10-02-2009
Thanks cfa! I'll give that a try. Any tips on converting the Jul 29 to 0729 or Oct 2 to 1002?
# 5  
Old 10-02-2009
Quote:
Originally Posted by linux_lou
Thanks cfa! I'll give that a try. Any tips on converting the Jul 29 to 0729 or Oct 2 to 1002?

Code:
month=Jul
day=29

mm=JanFebMarAprMayJunJulAugSepOctNovDec
idx=${mm%%$month*}
mnum=$(( (${#idx} + 4 ) / 3 ))
printf "%02d%02d\n" "$mnum" "$day"

# 6  
Old 10-02-2009
or a more brute force solution
Code:
  case $month in
  (Jan) m=1;;
  (Feb) m=2;;
  (Mar) m=3;;
  (Apr) m=4;;
  (May) m=5;;
  (Jun) m=6;;
  (Jul) m=7;;
  (Aug) m=8;;
  (Sep) m=9;;
  (Oct) m=10;;
  (Nov) m=11;;
  (Dec) m=12;;
  esac

# 7  
Old 10-09-2009
Thank you Folks!

---------- Post updated at 04:20 PM ---------- Previous update was at 09:36 AM ----------

while read i
do
: whatever
done < list

When I tried this example, the program ran the first line as expected and did not advance to the second. Tried it with the ":" and without, same results.

while read i
do
: ans=`rexsh $i -l bozo -t10 uptime | cut -d" " -f6`
echo "$i|$ans" >>bootTimes.out

if [ $ans -ge 120 ]
then
echo "$i|$ans" >>bootThese.out
else
echo "$i|$ans" >>bootList2Recent2Work.out
fi

done < list
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Df -h results in a loop

Hello everyone, I am doing a check of the disk space using df -h, I want to combine the result in break line; but the result after while/done is empty: # df -h Filesystem Size Used Avail Use% Mounted on rootfs 20G 14G 4.6G 75% / /dev/root 20G 14G 4.6G 75% /... (15 Replies)
Discussion started by: Abu Rayane
15 Replies

2. Shell Programming and Scripting

Narrowing sed Results in While Loop

find $SRC -type f -name *.emlx | while read FILE do if : then sed -n '/From/p' $FILE fi done > $DEST-output.txt The loop above spits out a .txt file with several lines that look like this: From: John Smith <jsmith@company.com> How can I narrow that sed result to spit out the email... (5 Replies)
Discussion started by: sudo
5 Replies

3. Shell Programming and Scripting

Loop through awk results

I have files structured in stanzas, whose title is '', and the rest couples of 'id: value'. I need to find text within the title and return the whole stanzas that match the title. The following works: awk 'BEGIN{RS="";IGNORECASE=1}/^\/' myfileI would need to count all of the occurences, though,... (7 Replies)
Discussion started by: hermes14
7 Replies

4. Shell Programming and Scripting

Concatenate Loop Results

Hi, I have the following situation: Param1Values = AAAA,BBBB Param1=$(echo $Param1Values| tr "," "\n") for x in $Param1 do db2 select X from Y where Z IN ('$x') done Obviously the above will perform the select 'x' amount of times. Is there a way in which i can... (13 Replies)
Discussion started by: RichZR
13 Replies

5. Programming

How to take input from cmd line into file

Hi, I want to be able to write a simple program that takes in input from the command line. I;m am at the level of getchar and putchar. Any examples would be a great help thanks. I intend/prefer also to use the pipe command | eg: input | file1 ---------- Post updated at 04:08 PM ----------... (4 Replies)
Discussion started by: metros
4 Replies

6. Shell Programming and Scripting

doing a for loop adding up the results

Hi there If I run a 'swap -l' on my solaris box, i get swapfile dev swaplo blocks free /dev/dsk/c1t0d0s1 54,65 8 67119560 65655144 /dev/dsk/c1t0d0s2 54,65 8 33119522 32655122 I wanted to run a for loop adding up the totals of each column 4 , excluding the... (2 Replies)
Discussion started by: hcclnoodles
2 Replies

7. Solaris

Reset ILOM from cmd line

One of our T5220 console is not working & unable to login to ILOM , but system is up & running . is there a way to reset ILOM from command line ? (8 Replies)
Discussion started by: skamal4u
8 Replies

8. Shell Programming and Scripting

Removing tokens from cmd line

Hi everyone. I am trying to develop my own shell,and i am in the part of redirection. let's say the user gives as input cat test > test2 in the array of arguments i want to keep only arg=cat,arg=test. ">" token is not an input file so cat cannot worka and test2 is output.how can i remove > and... (1 Reply)
Discussion started by: bashuser2
1 Replies

9. Shell Programming and Scripting

works from cmd-line but not in script

hi I'm trying to query a directory, check it's the right directory, return the results into a text file, put text file into an array and navigate the subdirectories and delete contents. find `pwd` -type d | grep TESTINGDIR > dirList.txt The txt file is created from the cmd-line but not in... (4 Replies)
Discussion started by: OFFSIHR
4 Replies

10. Shell Programming and Scripting

Perl - Iterating a hash through a foreach loop - unexpected results

i've reworked some code from an earlier post, and it isn't working as expected i've simplified it to try and find the problem. i spent hours trying to figure out what is wrong, eventually thinking there was a bug in perl or a problem with my computer. but, i've tried it on 3 machines with the... (5 Replies)
Discussion started by: quantumechanix
5 Replies
Login or Register to Ask a Question