How to preserve gawk in ssh?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to preserve gawk in ssh?
# 1  
Old 04-02-2013
How to preserve gawk in ssh?

I am trying to extract some information out of a policy listing command. I have the following:

Code:
for server in test1 test2; do ssh $server '/usr/listinfo policy -L |gawk 'NR == 2'';done

This runs without the awk and sshs to remote server, but with the gawk then I get gawk command not found. How do I make sure the gawk is picked up? Is there a way to avoid the pipe?
# 2  
Old 04-02-2013
This has two problems.

First and foremost, you cannot nest single quotes in single quotes. You can't escape anything in single quotes either, so not even backslashes will fix it. You'll have to put double quotes on the outside.

Second, not all systems have gawk. In fact very few systems have gawk; even systems like Linux which default to it just call it awk.

Your awk command is simple enough that hopefully vanilla awk can handle it, even the awful old versions some systems have.

Code:
for server in test1 test2; do ssh $server "/usr/listinfo policy -L | awk 'NR == 2'";done

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to preserve the value of a variable from being overwritten?

Hi All, I am new new to unix.com, I have a question related to shell scripting. We have a Oracle database backup shell script, which can be used for taking full, incremental & archive log backup based on the parameters passed. Within the script we export a variable as export... (5 Replies)
Discussion started by: veeresh_15
5 Replies

2. Shell Programming and Scripting

awk - How to preserve whitespace?

Given a file: # configuration file for newsyslog # $FreeBSD: /repoman/r/ncvs/src/etc/newsyslog.conf,v 1.50 2005/03/02 00:40:55 brooks Exp $ # # Entries which do not specify the '/pid_file' field will cause the # syslogd process to be signalled when that log file is rotated. This # action... (10 Replies)
Discussion started by: jnojr
10 Replies

3. Shell Programming and Scripting

Preserve value between different run of script.

I have a script that test for server up status. I need to preserve the value of status between every run of the script. test.sh log=$(cat /tmp/log_status) start loop test for servers print status for munin etc test=$(echo -e "${test}${status},") end loop echo $test >... (4 Replies)
Discussion started by: Jotne
4 Replies

4. Programming

Ways to preserve a memory cache

The environment is Java/Windows. The program keeps near real-time state in memory cache, which is updated by multiple sources, size of the cache is roughly 500 MB, frequency of updates is ~ 20 per second. I am looking into different ways to keep current snapshot of the memory on the disk for a)... (9 Replies)
Discussion started by: migurus
9 Replies

5. Shell Programming and Scripting

Using expect doesn't preserve the stderr

Hello, I am performing the follwing line from a unix server: expect -c 'spawn ssh otherHost chown -R user:group /usr ; expect password: ; send 123456\n ; interact ;' I am getting return value 0, an empty stderr and a stdout that says "/usr/... Not owner, /usr/... Not Owner ..". If I... (2 Replies)
Discussion started by: lastZenMaster
2 Replies

6. Shell Programming and Scripting

Unable to preserve hard links. Why?

Hi, I'm trying to create a Makefile that would automate remastering Knoppix distribution. As a part of the process I am mounting using linux cloop device a compressed filesystem and copy the content out of it to separate dir. However during that process I need to preserve hard links and it... (9 Replies)
Discussion started by: dpc.ucore.info
9 Replies

7. UNIX for Advanced & Expert Users

update files and preserve date

I have a bunch of historical files that need to be modified, as the file source announced there is an error in them which should be corrected. I am planning to use sed to do the mass update, but I would like to know if there is a way to preserve files last modified date/time, so later ls -ltr... (3 Replies)
Discussion started by: migurus
3 Replies

8. Shell Programming and Scripting

Preserve first line and search in others

Hi gurus Is possible to preserve first line of text and search in another lines ? the only way that I think is: ps aux | awk '{if (NR==1) {print $0} else if ($11 ~ /sshd/) {print $0}}' but is there any more elegant way ? thanks (4 Replies)
Discussion started by: wakatana
4 Replies

9. Shell Programming and Scripting

How to preserve NL in Ksh variables?

I'm trying to set a variable to the output of a command. This is what the comand output to the display looks like: />hciconndump -v TOsiu Dump of connection(s): TOsiu ---------------------------------------------------------------------- Process: A60Tsiu Connection: TOsiu... (2 Replies)
Discussion started by: troym72
2 Replies

10. Shell Programming and Scripting

preserve timestamp of symlinks using rsync

Hi, In my shell programming, When i copy sym links from one server to another server using rsync it does not preserve time stamp . it showing current time after copying in destination server.the command i used is rsync -vaR -- How can i preserve sym links time stamp using rsync. Thanx (1 Reply)
Discussion started by: KiranKumarKarre
1 Replies
Login or Register to Ask a Question