I'm trying to do some very basic scripting. I been scouring the board looking at examples but I just can't seem to piece something together.
Edit: Now that I look at it, maybe my request is a little more complex and I'm biting off more than I can chew...
1. Take a list of IPs/hosts (hosts.txt)
For each host:
1. Continually Ping with Timestamp
2. Append each in their own log file (host1.log, host2.log, host3.log)
3. Every 30 seconds perform an nmap -sP - Append another individual log file (host1-nmap.log, host2-nmap.log, host3-nmap.log)
4. Run this script maybe in crontab so that it keeps running until you run a "service stop"?
Honestly, I'm not entirely looking just for the answer, would just appreciate some tips, examples and kinda where to look.
For each host:
1. Continually Ping with Timestamp
2. Append each in their own log file (host1.log, host2.log, host3.log)
3. Every 30 seconds perform an nmap -sP - Append another individual log file (host1-nmap.log, host2-nmap.log, host3-nmap.log)
4. Run this script maybe in crontab so that it keeps running until you run a "service stop"?
Let us start with 1.: Because commands in a script are only processed sequentially you will have to send the jobs in the background to have them run concurrently:
2. is quite simple, just add a redirection:
For 3. set up a second loop:
That leaves the starting/stopping issue. I'd use a PID file in "/var/run" and use that to eliminate the process:
I hope this helps.
bakunin
Last edited by bakunin; 10-30-2012 at 01:35 PM..
Reason: corrected typo
So, I had gotten close to the list thing stumbling through, but essentially took your advice verbatim and did the following:
Which works great. But I noticed it was a bear to try and do any sort of PS since it spawned so many. The second PID portion of your suggestion REALLY has my head spinning and thus I'll need to re-read it.
So, in the meantime, I've just adjusted the script to do the following (which is probably a better I idea anyway)
The second PID portion of your suggestion REALLY has my head spinning and thus I'll need to re-read it.
As much as i would like to take the praise for this idea: it is common within many UNIX programs (daemons mostly) to create a file with the PID (process ID) in /var/run at the start and use the PID stored there to shut down the process.
Hi All,
I'm trying to write while loop with multiple if conditions. Each and every if condition with different variables. whenever one if condition fails i have remove the file
from filename and have to pick another file and loop should exit until the last file found in filename. Please help... (4 Replies)
Hi All
I need really really help with this :-
I have two files ( File1 , File 2) both files are output of two different scripts.
File1 usually has a list of names ( sometimes 3 names sometimes 5 sometimes more , depends about the output of the script)
File2 usually has a list of numbers... (2 Replies)
Hi,
I want to read file multiple times. Right now i am using while loop but that is not working.
ex.
While read line
do
while read line2
do
echo stmt1
#processing some data based on data.,
done < file2.txt
done < file1.txt # This will have 10... (4 Replies)
Hi,
I have two variables like below which will always be of the same size
a=1:2:3
b=A:B:C
I need to use a for/while loop that will have both the variables available. I cannot use an array here and will probably might iterate through the variable as echo $a | tr ':' '\n' and thus iterate... (5 Replies)
I am in the process of updating a folder of hundreds of recipe html files. I've already managed to modify a number of things in each file but I have run into something that's beyond my ability.
I have a text file that I need to insert the contents into the html at a specific point. It creates... (0 Replies)
Hi,
How can I avoid multiple 'cat while read ....? in my script.
In my script, I am taking the inputs from the temp text file and doing the
(
cat while read input
do
...
...
done
)
task and deleting later.
I know it'll raise the perfomance issue. How to avoid this? (2 Replies)
Hi
I have these data
0.9>i>0.1
0.45>j>0.01
I want to execute the script file for different number of i and j using the command
$ ./scriptfile i j
I write this code
#bin/bash
for ((i>0.1; i<0.9; i++))
for ((j>0.01; j<0.45; j++))
do
./scriptfile $i $j
done
However, for loop is not... (3 Replies)
Hi ,
I am trying to write a script in kshell with while loop ,its like
count=1
count_cmp=1
while ; do
tail -$count tempfile | head -1 > tempstring
.......
done
However i get CIF.sh: line 33: '
I have checked thetrailing spaces , not sure what is... (4 Replies)
I have a script which selects two 'sets' of system LVM device files from a tabular file 'mapfile' using awk :
LIVELV=`awk '{print($1)}' mapfile`
BCVLV=`awk '{print($3)}' mapfile`
I wanted to pass these 'sets' into an LVM command 'loop' along the lines of :
lvmerge $BCVLV $LIVELV
ie.... (3 Replies)