Q=What will this do? A=This will read from /root/Desktop/iplist (or anywhere you want to put the list) after it reads the ip it will ping the ip two times. If the remote host is up then it will write the ip to a log. If the ping fails it will display it on the screen, write the ip to syslog so that you can do remote logging, and last it will send the ip by email to a user or a group of users.
Code: #!/bin/bash #wrote by Zach Underwood feb-12-2011 #test and wrote on centos 5.5 with sendmail rm -f /root/Desktop/iplog #This will remove the good iplog exec 9</root/Desktop/iplist #put full path the file where ip list is. Make sure that the ips are listed one per line. while read -u9 ip do ping -c 2 $ip > /dev/null 2> /dev/null # ping and discard output if [ $? -eq 0 ]; then # check the exit code echo "$ip is up" >> /root/Desktop/iplog #write the ip of the hosts that are up else echo "$ip is down" # will show on the screen the ips that are not up logger -p auth.notice "$ip is down" # will write the down host to syslog echo "$ip is down" | mail -v -s alert email@example.com > /dev/null 2> /dev/null #will send mail users about host down fi done
I've searched everywhere and I can't come up with a good solution. For each line I need to find the average, min, and max. I've seen plenty of solutions where the number of columns is fixed, unfortunately for me these lines can get pretty large. My thought was to read each line individually into an array, loop through the array and find the avg, min, and max that way but i haven't had much luck. I can read each line using a while loop but I'm having trouble with the array part, or perhaps that's not the best solution?
I have a script almost working except for 1 thing. What I'm trying to do is read a file that has the files that need to be FTP'd using a bash script. I have everything working except the reading of the file. It works outside of the ftp script I've wrote but once I put it in the FTP script it doesn't.
Here's the Script:
#Here's where the problem is that I know of
I've been playing w/ the exclamation points to see if that could be the problem, but so far no luck.
I have a text file that contains a single word and I want to write a bash script that will read the word from the text file... The following is my incorrect attempt, as it assigns the name of the textfile to the variable as opposed to the word stored within the textfile:(assume I have a text file value.txt that has its contents a single word, say wordone)
Code: #!/bin/sh for f in value.txt do echo $f done
so the output of the above script is value.txt, however I want it to be wordone.to summarise: how do I assign the value of the word contained within a textfile to a variable?
I am trying to write a program that gets file permission. I understand linux has ls -l can view file permission, but it has too many information that I have to process those strings in my program. Is there an easier command just return me the permission digits like: $ getperm /home/file 0440 $
What are the possible problem when Windows access the file from Ubuntu got Read Only even though have a full permission to read, write and execute the file? Ubuntu to Ubuntu accessing the file there is no problem only Windows got a problem.
I have a script that reads part of a line, delimited between the first and second intended part by a colon. Then it "chops" the part after the colon, which are words offset by commas (counting them beforehand so as to catch every word in the string's second part), like this:
"COLORS.JPG:red,orange,yellow,green," (Returning) red
single script that parses/breaks both parts of a line like this "COLORS.JPG:red,orange,yellow,green;blue,indigo,violet," so that the two parts, separated into single words (or two and three words, sometimes with spaces) can be used as single-line annotations and written to JPEG files using Exiv2. So far, I haven't been able to come up with a script that does this without one part of the total string(usually that part after the colon) becoming the first word in the second array. In other words, I look for this:
[ ]red [ ]orange [ ]yellow
Or vice-versa (ie, the second array winds up as a single-line "member" of the first). I think it's because I'm using a single while read loop to read the text file in which the filenames and substrings happen to be. If there's some way of reading a file once and going back to the beginning to read it again in another while loop, I haven't found it.
I am struggling with Bash scripting at the moment (I can't seem how anyone can write scripts with this language!!!) I have a need at home to have a cron job execute daily to lookup my downloads.txt file, read each url (per line) and download content from that url. Then that entry needs to be removed (well I keep all urls in memory and clear the file afterwards). If an error occurred during the download process, then the url is written to a downloads.err file. I got all the above working except for properly reading the url from the text file without including newline characters. I am using the following to read:
while read url; do --Do whatever here-- done < downloads.txt
How can I get it not to let the url variable have newline characters?
I googled and tried to find an easy step by step-by-step guide on how to use a bash script read a variable from a file. This is the way I did it (but it does not really work so something is wrong, but what?) (testfil2 contains one line that readsidnumber=1578
At my wit's end I can't find anything that I understand well enough to use. This is for a Unix class, we are working with shell scripting. File1 has 5 in it and File2 has 100 in it.The teacher wants us to read the values then do the math. This is what I have so far:#!/bin/bashvar1='cat File1'var2='cat File2'var3=`echo "scale=4; $var1 / $var2" | bc`echo The final result is: $var3
So far so good. Now, I want to define two variables (e.g. e1,e2) in the bash file, so that their values would correspond to 00.00 and 30.00, as read from the input file. This one I have not found yet, thus asking for your advice. At the end, writing echo $e1 $e2, I should get 10.00 30.00 This is even harder to me: I want to replace the values emin,emax in a new file "modify.dat" which looks like that:
with the values e1 and e2 I have in my bash file. In other words, I want to call "modify.dat", find these two lines and replace the numeric values with the e1 and e2. At the end, my file should be like:
I need a bash script that can read from a MySQL database field and insert the read information into a variable. I need it to read from a field in the database which will list if somone is using Linux or Windows. Once its done that the code will continue as follows:
if [ "$var" = "linux" ] ; then OTHER CODE HERE else
Code: #!/bin/bash trap "echo 'you got me'" SIGINT SIGTERM # to trap ctrl+c echo "Press ctrl+c during 5 sec loop" for ((i=0;i<5;i++)); do
How come code behaves normally and stops when ctrl+c signal is caught and resumes, but after I use at least one timeout read in the code it looks like, if signal is caught again it doesn't pause the execution but skips the loop. If you remove -t (timeout) option from the read, both loops look the same!
bash 3.1.17(2) I'm trying do write a shell script which must operate on each line of an ASCII text file. So, all the code must be inside a loop, and inside the loop, the first thing should be to read the next line from the file. I have the bash read command. But it reads from stdin. Any way to make read from a file?
I had a script once that had in it a while true; do and read lines or data from a file similarly to a while read; do. I have a script I'm working on now where I'm trying to "prove the negative" that certain substrings culled from one file do not appear in another file. I'll try to explain what I mean with an example. An item in one list might be
But the other list may only have
harvey1996nicks:Six stores in north London harvey1997nicks:Three stores in Bristol harvey1999nicks:Eight stores in the lower Midlands
The problem is, other items in the first list do match items in the second. The script I'm drawing this from has already pulled those out and written them to one (or several) lists that I've been able to use with other programs (Exiv2 specifically). The furthest I've bothered to go in the direction of "proving the negative" is a slow "if/then/fi" loop that looks like this:
linecheck=$[linecheck+1] if [[ "$linecheck" == "$axe" ]] && [[ "$matchX" == "" ]]; then echo -e $file>>nomatches.txt; fi
linecheck is counting the lines of the second file -- the one with the designations or "labels" (the "so many stores in ..." from my example) -- as they are checked against the file names in the first (the "harvey199*nicks.jpg" etc of my example. axe is the number of lines in that first list (culled from a cat |wc -l at the beginning of the script). matchX is the variable the "prove the positive" script used for matches, one list to the other, which then got written line by line to a text file.
i'm new to linux and i am running ubuntu 11.04.i'm trying to install wine. i downloaded the binary files and extracted them. i tried running the command './configure' and got a error saying :no such file or dir. i read the 'readme' file but cannot configure.
I'm storing a list of strings in a file and would like to read the file and pipe each line returned to grep which in turn searches a directory for files containing the string.However this is not returning any output.