Need script to compare and redirect


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need script to compare and redirect
# 1  
Old 01-20-2013
Need script to compare and redirect

Hi,
I have a file, sol_servers_global, which is list of all solaris global servers in my environment and another file,
solaris_non_global_zones_from_DB. I have a gateway server, from where all servers are contactable via ssh. I have collected name of zones running on these servers with below commands.
HTML Code:
for i in `cat sol_servers_global`; do sudo ssh $i zoneadm list | grep -v global >>/var/tmp/all_zones; done
My basic idea is to prepare a script, which should -->
1- Capture zones running on servers listed on sol_servers_global (May be I can run for loop listed above)
2- Compare both files and list out zones which are not in solaris_non_global_zones_from_DB, but present in /var/tmp/all_zones and redirect to /var/tmp/servers_not_in_db.
3- Compare both files and list out zones which are not in /var/tmp/all_zones, but present in solaris_non_global_zones_from_DB and redirect to /var/tmp/servers_not_exist.
I was trying to compare it with below commands. If you have any easy and better compare tool, please suggest that too.
HTML Code:
awk 'FNR==NR{a[$0];next} !($0 in a)' solaris_non_global_zones_from_DB /var/tmp/all_zones >>/var/tmp/servers_not_in_db
awk 'FNR==NR{a[$0];next} !($0 in a)' /var/tmp/all_zones solaris_non_global_zones_from_DB >>/var/tmp/servers_not_exist
I was doing it manually. It is very frequent so it takes long time to do it. If somebody can help me with script, it will be easy for me to do it fast.

Regards
# 2  
Old 01-20-2013
you could try the -vxf pattern_file grep arguments instead of your awk code: eg:

Code:
while read server
do
   sudo ssh $server zoneadm list
done < sol_servers_global | grep -v global > /var/tmp/all_zones
 
grep -xvf solaris_non_global_zones_from_DB /var/tmp/all_zones > /var/tmp/servers_not_in_db
grep -xvf /var/tmp/all_zones solaris_non_global_zones_from_DB > /var/tmp/servers_not_exist

# 3  
Old 01-21-2013
This script stops at first server only from list sol_servers_global and redirect zones of only first server to /var/tmp/all_zones.
Am I missing something in it ?
# 4  
Old 01-21-2013
What shell are you using?

This seem to work fine in my tests with bash and ksh:

Code:
$ cat sol_servers_global 
server1
server2
server3
 
$ while read server
do
    echo Server $server read
done < sol_servers_global | grep -v global
Server server1 read
Server server2 read
Server server3 read

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 redirect the messages from the script to console in Linux?

msg.sh #!/bin/bash if then echo "starting service" else echo " service not started" echo " Please check the start.sh file or manuly start the service" fi if i login with root credentials @12.36.34.123 with passwd username:root passwd:abc once i login into linux pc... (6 Replies)
Discussion started by: saku
6 Replies

2. Shell Programming and Scripting

Script to call a menu script and redirect each option to a text file

Hello, I want to design a script that will call an existing menu script and select options one by one and redirict the out put to a file. For example;- In the script MENU.sh there are 10 options i want to design a script MENU2.sh that will select option 2 3 4 6 7 10 and redirict the output... (4 Replies)
Discussion started by: spradha
4 Replies

3. Shell Programming and Scripting

PHP Redirect Script

Hello Unix.com, I badly need to get rid of drones that access my website. I'm using a hits php script that logs every ip that visits my index.php. Looks like this: <?php $IP = getenv("REMOTE_ADDR"); $day = date('l jS \of F Y h:i:s A'); $fout = fopen("hits.txt", "a"); fputs($fout,... (0 Replies)
Discussion started by: galford
0 Replies

4. Shell Programming and Scripting

Redirect the output in shell script for tftp

I've been using tftp in one of my file #!/bin/bash filename1="config1h.txt" filename2="config15.txt" hostname="test.com" tftp $hostname <</dev/null get $filename1 get $filename2 quit EOF My output looks like this # ./test3.sh tftp> Received 1262 bytes in 0.0 seconds tftp> Received... (2 Replies)
Discussion started by: LavanyaP
2 Replies

5. Shell Programming and Scripting

Cannot redirect to STDIN in a shell script

I am unable to use STDIn redirection with < (commands) When I do the following, both approaches work and give the same results: 1. $ printf "aaa\nbbb\n" > file1 $ printf "111\n222\n" > file2 $ cat file1 file2 aaa bbb 111 2222. $ cat <(printf "aaa\nbbb\n") <(printf "111\n222\n") aaa... (8 Replies)
Discussion started by: metaltree
8 Replies

6. UNIX for Advanced & Expert Users

Redirect ErrorLog to a script

Hello, guys! I need to redirect the error_log of apache web server to a script. I tried to use a pipe instead of a filename but this will cause me some troubles beacause cPanel doesn't like it. So, I would like to try something else. Do you have any ideea on how can I read the content of the... (2 Replies)
Discussion started by: Sergiu-IT
2 Replies

7. Shell Programming and Scripting

Redirect bg process output to within the script

Hi, I have a process running in the background, which throws up some output to the terminal when I run my script. How can I read this output from my script? Thank you. (5 Replies)
Discussion started by: Theju
5 Replies

8. Shell Programming and Scripting

compare and redirect to new file

hi i have two file a.txt 123,b,c,d,e 111,c,d,e,f, 456,a,k,j,h b.txt 123 678 987 321 456 i want to compare these two files(match content of b first coloum with a ) and o/p should be like 123,d,e 456,j,h pls help.....:) (7 Replies)
Discussion started by: anish19
7 Replies

9. Shell Programming and Scripting

How redirect script output from inside of script?

Is it possible to redirect a script output by command inside of that script? I mean, if I have a script 'dosome.sh' I could run it by >dosome.sh > dosome.log I would dream to get some command inside of scrip to do the same; so, running the dosome.sh would have all output redirected to a log... (4 Replies)
Discussion started by: alex_5161
4 Replies

10. Shell Programming and Scripting

Search--Compare--Redirect

Hai Guru's, I have 3 files.A,B,C The file A,B is very huge.What i need to do is...I just get each record from file A and compare with File B...if the record presents...redirect the record to File C..otherwise not needed... Kindly give me ur valuable suggestions to resolve the above... (1 Reply)
Discussion started by: satheesh_color
1 Replies
Login or Register to Ask a Question