How to append server name to everyline?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to append server name to everyline?
# 1  
Old 11-22-2013
How to append server name to everyline?

I am executing df -mP to see the disk utilization.
I would like to append servername also to each and every line.

Code:
 
df -mP |  awk '{ print $1","$2","$3","$4","$5","$6 }'


trying to add something like this

Code:
 
df -mP |  awk '{ print $1","$2","$3","$4","$5","$6","$hostname }'

to get the hostname along with the output but could not succeed .

Need help on this
# 2  
Old 11-22-2013
Quote:
Originally Posted by lazydev
I am executing df -mP to see the disk utilization.
I would like to append servername also to each and every line.

Code:
 
df -mP |  awk '{ print $1","$2","$3","$4","$5","$6 }'


trying to add something like this

Code:
 
df -mP |  awk '{ print $1","$2","$3","$4","$5","$6","$hostname }'

to get the hostname along with the output but could not succeed .

Need help on this
Try:
Code:
df -mP | awk -v hostname="$(hostname)" '{print $1","$2","$3","$4","$5","$6","hostname}'

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

--Parsing out strings for repeating delimiters for everyline

Hello: I have some text output, on SunOS 5.11 platform using KSH: I am trying to parse out each string within the () for each line. I tried, as example: perl -lanF"" -e 'print "$F $F $F $F $F $F"' But for some reason, the output gets all garbled after the the first fields.... (8 Replies)
Discussion started by: gilgamesh
8 Replies

2. Shell Programming and Scripting

How to Append the output of a script running in remote server to a file in local server?

Hi guys, So i am in server1 and i have to login to server 2, 3,4 and run some script there(logging script) and output its result. What i am doing is running the script in server2 and outputting it to a file in server 2 and then Scp'ing the file to server1. Similarly i am doing this for other... (5 Replies)
Discussion started by: srkmish
5 Replies

3. UNIX for Dummies Questions & Answers

Transfer file from server B to server C and running the script on server A

I have 3 servers A, B, C and server B is having some files in /u01/soa/ directory, these files i want to copy to server C, and i want to run the script from server A. Script(Server A) --> Files at Server B (Source server) --> Copy the files to Server C(Target Server). We dont have RSA key... (4 Replies)
Discussion started by: kiran_j
4 Replies

4. Shell Programming and Scripting

Connect to server-1 from server-2 and get a file from server-1

I need to connect to a ftp server-1 from linux server-2 and copy/get a file from server-1 which follows a name pattern of FILENAME* (located on the root directory) and copy on a directory on server-2. Later, I have to use this file for ETL loading... For this I tried using as below /usr/bin/ftp... (8 Replies)
Discussion started by: dhruuv369
8 Replies

5. Shell Programming and Scripting

KSH fetching files from server A onto server B and putting on server C

Dear Friends, Sorry for this basic request. But I just started learning Ksh recently and still I am a newbie in this field. Q: I have files on one server and the date format is 20121001000009_224625.in which has year (yyyy) month (mm) and date (dd). I have these files on server A. The task... (8 Replies)
Discussion started by: BrownBob
8 Replies

6. UNIX for Advanced & Expert Users

Collect files from different servers to a single server and append them

Hi, I have script1.sh on 3 servers. I want to collect output report generated by them to a single server and append all the reports. Please tell me how can i do this? (2 Replies)
Discussion started by: pratikm23
2 Replies

7. Shell Programming and Scripting

Awk new datetime everyline

Hi, I'm using awk in HP-UX machine which does not support systime(), strftime(). So to get the date time I was using : seq 1 100000 | awk ' "date +%Y%m%d%H%M%s" | getline curtime; print curtime }' However the above code gets the date only once, next time it is not updated. For... (2 Replies)
Discussion started by: Random_Net
2 Replies

8. Shell Programming and Scripting

cut columns in everyline

Is there a betterway to cut certain columns in everyline based on positions. Basically, I have a largefile and eachline is of 1000 characters and I need to cut the characters 17-30, 750-775, 776-779, 780-805 while do fptr=`cat $tempfile | head -$i | tail -1` ... (4 Replies)
Discussion started by: gunaah
4 Replies

9. Shell Programming and Scripting

append a ' to the $1 $2

Hi all , Iam trying to append a ' to the end of the $1 and $2 in the bellow example : awk '{print "exec upload" ,$1,$2,$3 "\ngo"}' so the output would be something like this : exec upload '444042 ','444042 ','919841037265' i am getting : exec upload 444042 ,444042 ,919841037265 ... (2 Replies)
Discussion started by: ppass
2 Replies

10. Shell Programming and Scripting

Text Append

I'm creating a script that counts the number of users currently online, then records that in a file called "log.txt" along with the time. Everytime the script is ran, the script appends the "log.txt" this is what I have: who|wc|cut -c6,7>>log.txt date|cut -c12-24>>log.txt After running... (5 Replies)
Discussion started by: 801238429
5 Replies
Login or Register to Ask a Question