Sponsored Content
Top Forums UNIX for Advanced & Expert Users Read file and skip the line starting with # Post 302787263 by rangarasan on Friday 29th of March 2013 04:47:38 AM
Old 03-29-2013
Quote:
Originally Posted by hanson44
I think this will skip the servers with the # in front:
Code:
#!/usr/bin/sh
file2put=$1
if [ -f $file2copy ]; then
  echo "File found, preparing to transfer... \n"
  grep -v '^#' server.cfg > valid_servers
  while read line; do
    ssh $line < checkdirectory.sh #another script to check the existing of directory
    scp $file2put $line:~/folder_name/$file2copy
  done < valid_servers
  exit
else
  echo "File does not exist. Exiting..."
  exit 
fi

Hey!!!

Do you really want to create a physical file "valid_servers"? Instead, we can just redirect the output of grep to while loop.

Code:
egrep -v '^#|^$' file1|while read server_name
do
    echo "$server_name"
    # File transfer goes here
done

Cheers,
RangaSmilie
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to skip first line from a file while manupulating the file

I need to put single quotes on the columns of a .csv file. The first row contains the column headers. I need to skip the first row and put quotes for rest of the rows. Would please someone help me with this. Thanks JP (4 Replies)
Discussion started by: JPalt
4 Replies

2. Shell Programming and Scripting

bash: read file line by line (lines have '\0') - not full line has read???

I am using the while-loop to read a file. The file has lines with null-terminated strings (words, actually.) What I have by that reading - just a first word up to '\0'! I need to have whole string up to 'new line' - (LF, 10#10, 16#A) What I am doing wrong? #make file 'grb' with... (6 Replies)
Discussion started by: alex_5161
6 Replies

3. Shell Programming and Scripting

Read .txt file and dropping lines starting with #

Hi All, I have a .txt file with some contents as below: Hi How are you? # Fine and you? I want a script file which reads the .txt file and output the lines which does not start with #. Hi How are you? Help is highly appreciated. Please use code tags when posting data and... (5 Replies)
Discussion started by: bghosh
5 Replies

4. UNIX for Dummies Questions & Answers

skip first line when doing a read of csv file

Folks, how do i skip the first line in a csv, while doing the read of a csv file in to a variable line by line. eg : do echo $line done < $rpt where rpt is path to csv file The initial 1st line is a garbage that i want to avoid, and start reading from 2nd line ... (2 Replies)
Discussion started by: venu
2 Replies

5. Shell Programming and Scripting

want to skip a line in XML file using awk

HI All, I am trying to split a xml using awk. now the issue is i want to skip three lines from the xml file. first two and last one based on pattern. plz some one help. i am new to awk and struggling :wall: <?xml version="1.0"?> <notification> ..... ..... ..... ..... ........ (24 Replies)
Discussion started by: ganesan kulasek
24 Replies

6. Shell Programming and Scripting

Need a program that read a file line by line and prints out lines 1, 2 & 3 after an empty line...

Hello, I need a program that read a file line by line and prints out lines 1, 2 & 3 after an empty line... An example of entries in the file would be: SRVXPAPI001 ERRO JUN24 07:28:34 1775 REASON= 0000, PROCID= #E506 #1065: TPCIPPR, INDEX= 003F ... (8 Replies)
Discussion started by: Ferocci
8 Replies

7. Shell Programming and Scripting

How to read file line by line and compare subset of 1st line with 2nd?

Hi all, I have a log file say Test.log that gets updated continuously and it has data in pipe separated format. A sample log file would look like: <date1>|<data1>|<url1>|<result1> <date2>|<data2>|<url2>|<result2> <date3>|<data3>|<url3>|<result3> <date4>|<data4>|<url4>|<result4> What I... (3 Replies)
Discussion started by: pat_pramod
3 Replies

8. Shell Programming and Scripting

How to read a file starting at certain line number?

I am new to ksh scripts. I would like to be able to read a file line by line from a certain line number. I have a specific line number saved in a variable, say $lineNumber. How can I start reading the file from the line number saved in $lineNumber? Thanks! (4 Replies)
Discussion started by: dcowboys13
4 Replies

9. Shell Programming and Scripting

With script bash, read file line per line starting at the end

Hello, I'm works on Ubuntu server My goal : I would like to read file line per line, but i want to started at the end of file. Currently, I use instructions : while read line; do COMMAND done < /var/log/apache2/access.log But, the first line, i don't want this. The file is long... (5 Replies)
Discussion started by: Fuziion
5 Replies

10. UNIX for Dummies Questions & Answers

How to grep a line not starting with # from a file (there are two lines starting with # and normal)?

e.g. File name: File.txt cat File.txt Result: #INBOUND_QUEUE=FAQ1 INBOUND_QUEUE=FAQ2 I want to get the value for one which is not commented out. Thanks, (3 Replies)
Discussion started by: Tanu
3 Replies
UNIX-GUIDE(1)							       mrtg							     UNIX-GUIDE(1)

NAME
unix-guide - Instructions for running MRTG 2.9.17 on a Unix Box SYNOPSIS
MRTG comes to you in Source Code. This means that you have to compile parts of it before you can use it on a Unix machine. These instruc- tions help you to do so. PREPARATION
In order to compile and use mrtg you need a C compiler and a copy of perl installed on your machine. In most cases this will already be available. In case it is not, here are some starting points. Below I'll give you a detailed run through the whole compilation process. GCC The GNU C compiler comes pre installed on most of the free Unicies out there. For commercial Derivats you may have to download and compile it first. If you have no compiler at all there is a chicken and egg problem, but there are also precompiled versions of gcc available for most of the operating systems. http://gcc.gnu.org/ Perl Larg parts of the MRTG system are written in the Perl scripting language. Make sure there is a recent copy of perl on your machine (try perl -v). At least version 5.005 is required for mrtg to work well. You can get the latest perl from http://www.perl.com/ MRTG generates traffic graphs in the PNG format. To be able todo this it needs several 3rd party libraries. When compiling these libraries I urge you to make sure you compile them as static libraries. There is just much less trouble ahead if you are doing it like this. See the Instructions in the next section for inspiration. Note that many free unices have all the required libraries already in place. So there is no need to install another copy. To check it is best to skip all the library instructions below and go straight into the mrtg compile. If the first attempt fails, and you do not get a working version of mrtg, try compiling new copies of all libraries as explained below ... Do this BEFORE you send email to me about problems compiling mrtg. gd This is a basic graph drawing library created by Thomas Boutell. Note that all releases after Version 1.3 only create PNG images. This is because a) Thomas got into trouble because the GIF format which it used to produce uses a compression technology patented by Unisys. b) PNG is more efficient and patent free. MRTG can work with old and new version of the GD library. You can get a recent copy of GD from: http://www.boutell.com/gd/ libpng Is required by gd in order to produce PNG graphics files. Get it from: http://www.libpng.org/pub/png/src/ zlib Finally is needed by libpng to compress the graphics files you create. Get a copy from ftp://sunsite.cnlab-switch.ch/mirror/infozip/zlib/ And last but not least you also need mrtg itself. In case you have not yet downloaded it, you can find a copy on my website: http://people.ee.ethz.ch/~oetiker/webtools/mrtg/pub/ LIBRARY COMPILATION
In this section I will give you step by step instructions on how to compile the various libraries required for the compilation of mrtg. Note that these libaries may already be installed if you have a *BSD or Linux system so that you can skip recompiling them. The wget pro- gramm used below is a simple web downloader you can also enter the address into your netscape if you don't have wget available. First lets create a directory for the compilation. Note that this may already exist on your system. No Problem just use it. mkdir -p /usr/local/src cd /usr/local/src If you do not have zlib installed: wget ftp://sunsite.cnlab-switch.ch/mirror/infozip/zlib/zlib.tar.gz gunzip -c zlib.tar.gz | tar xf - mv zlib-?.?.?/ zlib cd zlib ./configure make cd .. If you don't have libpng installed wget http://www.libpng.org/pub/png/src/libpng-1.0.11.tar.gz gunzip -c libpng-*.tar.gz |tar xf - rm libpng-*.tar.gz mv libpng-* libpng cd libpng make -f scripts/makefile.std CC=gcc ZLIBLIB=../zlib ZLIBINC=../zlib rm *.so.* *.so cd .. And now you can compile gd wget http://www.boutell.com/gd/http/gd-1.8.3.tar.gz gunzip -c gd-1.8.3.tar.gz |tar xf - mv gd-1.8.3 gd cd gd The characters at the end of the following lines mean that all the following material should actually be written on a single line. make INCLUDEDIRS="-I. -I../zlib -I../libpng" LIBDIRS="-L../zlib -L. -L../libpng" LIBS="-lgd -lpng -lz -lm" cd .. MRTG COMPILATION
Ok now everything is ready for the mrtg compilation. cd /usr/local/src gunzip -c mrtg-2.9.17.tar.gz | tar xvf - cd mrtg-2.9.17 If you all the libraries have been preinstalled on your system you can configure mrtg by doing a simple: ./configure --prefix=/usr/local/mrtg-2 Otherwise you may have to give some hints on where to find the various libraries required to compile mrtg: ./configure --prefix=/usr/local/mrtg-2 --with-gd=/usr/local/src/gd --with-z=/usr/local/src/zlib --with-png=/usr/local/src/libpng If you have RRDtool available you might want to tell mrtg about it so that you can opt to use rrdtool with mrtg. Check the mrtg-rrd man- page. Configure will make sure your environment is fit for building mrtg. If it finds a problem, it will tell you so and it will also tell you what todo about it. If everything is OK, you will end up with a custom Makefile for your system. Now type: make This builds the rateup binary and edits all the perl pathnames in the scripts. You can now install mrtg by typing make install All the software required by MRTG is now installed under in the /usr/local/mrtg-2 subdirectory. You can now safely delete the libraries we compiled above. But then again you might want to keep them around so that you have them avail- able when compiling the next version of mrtg. CONFIGURATION
The next step is now to configure mrtg for monitoring an network device. This is done by creating an mrtg.cfg file which defines what you want to monitor. Luckily you don't have to dive straight in and start writing your own configuration file all by yourself. Together with mrtg you also got a copy of cfgmaker. This is a script you can point at a router of your choice; and it will create a mrtg configuration file for you. You can find the script in the bin subdirectory. cfgmaker --global 'WorkDir: /home/httpd/mrtg' --global 'Options[_]: bits,growright' --output /home/mrtg/cfg/mrtg.cfg community@router.abc.xyz This example above will create an mrtg config file in /home/mrtg/cfg assuming this is a directory visible on your webserver. You can read all about cfgmaker in the cfgmaker manpage. One area you might want to look at is the possibility of using --ifref=ip to prevent interface renumbering troubles from catching you. If you want to start rolling your own mrtg configuration files, make sure you read the reference manpage to learn all about the possible configuration options. RUNNING MRTG
Once you have created a configuration file, try the following: /usr/local/mrtg-2/bin/mrtg /home/mrtg/cfg/mrtg.cfg This will query your router and also create your first mrtg trafic graphs and webpages. When you run mrtg for the first time there will be a lot of complaints about missing log files. Don't worry, this is normal for the first 2 times you start mrtg. If it keeps complaining after this time you might want to look into the problem. Starting mrtg by hand is not ideal in the long run. So when you are sattisfied with the results you must automate the process of running mrtg in regular intervals (this means every 5 minutes by default). You can either add mrtg to your crontab with a line like this: 0,5,10,15,20,25,30,35,40,45,50,55 * * * * <mrtg-bin>/mrtg <path to mrtg-cfg>/mrtg.cfg --logging /var/log/mrtg.log or if you live in Linux Land the line may look like this if you are using "crontab -e" */5 * * * * <mrtg-bin>/mrtg <path to mrtg-cfg>/mrtg.cfg --logging /var/log/mrtg.log or like this if you use /etc/crontab */5 * * * * mrtg-user <mrtg-bin>/mrtg <path to mrtg-cfg>/mrtg.cfg --logging /var/log/mrtg.log You can also run mrtg as a daemon process by adding the line RunAsDaemon: Yes to your mrtg configuration file and then creating a startup script in your system startup sequence. Unfortunately, adding startup scripts differs widely amongst different unix systems. The modern ones normally have a directory called /etc/init.d or /etc/rc.d/init.d where you put scripts which starts the process you want to run when the system boots. Further you must create a symbolic link in /etc/rc3.d or /etc/rc.d/rc?.d called S65mrtg (this is just a sample name ... it is just important that it starts with S followed by a two digit number). If you are not sure about this, make sure you consult the documentation of your system to make sure you get this right. A minimal script to put into init.d might look like this: #! /bin/sh cd /usr/local/mrtg-2.9.17/bin && ./mrtg --user=mrtg-user /home/httpd/mrtg/mrtg.cfg --logging /var/log/mrtg.log Note that this will only work with RunAsDaemon: Yes in your mrtg.cfg file. AUTHOR
Tobias Oetiker <oetiker@ee.ethz.ch> 3rd Berkeley Distribution 2.9.17 UNIX-GUIDE(1)
All times are GMT -4. The time now is 01:46 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy