SSH file redirection is not maintaining format


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting SSH file redirection is not maintaining format
# 1  
Old 05-05-2014
SSH file redirection is not maintaining format

Hi,

I'm running a script which would ssh to various ssh-trust enabled servers and get a list of packages installed. The output of this command would be redirected to a file

Code:
ssh -q $i 'rpm -qa --queryformat '%{NAME}\t\t,%{ARCH}\t\t,%{VERSION}-%{RELEASE}\t\t,%{INSTALLTIME:date}\n'|sed "s/^/`hostname`,\t\t/g" >> /tmp/`hostname`.PreUpdate.csv'

When I run this command locally on the server I get rows/columns

However, in ssh all the data is getting written to one Column

Any ideas
# 2  
Old 05-05-2014
Try replacing single quotes with doubles.
Code:
ssh -q $i "rpm -qa --queryformat '%{NAME}\t\t,%{ARCH}\t\t,%{VERSION}-%{RELEASE}\t\t,%{INSTALLTIME:date}\n'|sed "s/^/`hostname`,\t\t/g" >> /tmp/`hostname`.PreUpdate.csv"

# 3  
Old 05-05-2014
With double quotes at this level, the executing machine hostname will be prepended, instead of the one you ssh into. Because your machine's shell will evaluate whatever is inside the double quotes before passing it to ssh. example:

Code:
mute@hostA:~$ ssh mute@hostB "echo 'hello world' | sed \"s/^/`hostname`,\t\t/g\""
hostA,              hello world
mute@hostA:~$ ssh mute@hostB 'echo "hello world" | sed "s/^/`hostname`,\t\t/g"'
hostB,               hello world

I'd suggest just replacing the quotes used for --queryformat to double quotes.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Maintaining file structure

Hi guys, I am trying to store some output in a file and then compare it to another file. I am gathering information from 2 commands: cat /opt/jbin/server.log.tmp > A grep "ephemeral" /opt/jbin/log/server.log.2015-05-02-18 > B The contents of both file are the same. This means if I do a... (3 Replies)
Discussion started by: Junaid Subhani
3 Replies

2. Shell Programming and Scripting

Output redirection of c binary file to a file in shell script is failing

I am struck up with a problem and that is with output redirection. I used all the ways for the redirection of the output of c binary to a file, still it is failing. Here are the different ways which I have used: ./a.out | tee -a /root/tmp.txt 2>&1 ./a.out | tee -a /root/tmp.txt 1>&1 ./a.out |... (2 Replies)
Discussion started by: Maya29988
2 Replies

3. Shell Programming and Scripting

Maintaining file currency

I have a common data folder with files like x* which is accessed by 3 unix servers. Now each server will try to pick one file form this folder and move it to its local folder. How to maintain file concurrency in this case?I dont want the same file to be accessed by more than one process. (2 Replies)
Discussion started by: prasperl
2 Replies

4. Shell Programming and Scripting

how to format ssh top output

Hello; Am trying to generate runaway proc report using ssh thusly: =================== ssh -t -t $BOX 'TERMINAL="vt100" top -d1 -h -n 10' >> $FILE . . cat $FILE | mail -s "Latest Top `date`" $MAIL_TO ==================== But the output to e-mail comes out rather garbled .. Any ideas... (1 Reply)
Discussion started by: delphys
1 Replies

5. Shell Programming and Scripting

ssh and redirection

hi, i was using with success the following rsh statement : rsh server -l user1 "> /var/spool/mail/user1" to clear all the mail by remote now i try to do the same with ssh without success : ssh -t newuser@server "sudo -u user1 '> /var/spool/mail/user1'" i'm not authorized to... (17 Replies)
Discussion started by: Nicol
17 Replies

6. Red Hat

Copy certain file types recursively while maintaining file structure on destination?

Hi guys, I have just been bothered by a fairly small issue for some time now. I am trying to search (using find -name) for some .jpg files recursively. This is a Redhat environment with bash. I get this job done though I need to copy ALL of them and put them in a separate folder BUT I also... (1 Reply)
Discussion started by: rockf1bull
1 Replies

7. Shell Programming and Scripting

Converting windows format file to unix format using script

Hi, I am having couple of files which i used to copy from windows to Linux, so now in case of text files (CTRL^M) appears at end of line. I know i can convert this windows format file to unix format file by running dos2unix. My requirement here is that i want to do it automatically using a... (5 Replies)
Discussion started by: sarbjit
5 Replies

8. Shell Programming and Scripting

Net::SSH::Perl ...... how to print the output in a proper format

Hi Guys, my $cmd = "ls -l"; #........ {or let it be as # my $cmd= "ls"; } my $ssh = Net::SSH::Perl->new($host); $ssh->login($user, $pass); my($stdout, $stderr, $exit) = $ssh->cmd("$cmd"); print $stdout; the script works fine, but i am unable to see the output getting displayed in a... (7 Replies)
Discussion started by: gsprasanna
7 Replies

9. UNIX for Dummies Questions & Answers

To convert multi format file to a readable ascii format

Hi I have a file which has ascii , binary, binary decimal coded,decimal & hexadecimal data with lot of special characters (like öƒ.ƒ.„İİ¡Š·œƒ.„İİ¡Š· ) in it. I want to standardize the file into ASCII format & later use that as source . Can any one suggest a way a logic to convert such... (5 Replies)
Discussion started by: gaur.deepti
5 Replies

10. UNIX for Dummies Questions & Answers

File redirection

Is it possible to sh a command and receive the standard output on the scrren and use file redirection ie ls -lt > test. Also On SCO-UNIX there was a tellme command which displayed a message when a script had finished running is there something similar for HP UNIX as it is not working. (4 Replies)
Discussion started by: namtab
4 Replies
Login or Register to Ask a Question