Links

   Quran Explorer - Interactive Audio Recitations & Translations
Showing posts with label fedora. Show all posts
Showing posts with label fedora. Show all posts

Thursday, July 11, 2013

The LEGENDARY grep command


the man page starts as follows...
 
SYNOPSIS
       grep [OPTIONS] PATTERN [FILE...]
       grep [OPTIONS] [-e PATTERN | -f FILE] [FILE...]

DESCRIPTION
       grep  searches  the named input FILEs (or standard input if no files are named, or if a single hyphen-minus (-) is given as file name) for lines containing a match to the given PATTERN.  By default, grep prints the matching lines.

       In addition, two variant programs egrep and fgrep are available.  egrep is the same as  grep -E.   fgrep  is  the  same  as grep -F.   Direct  invocation as either egrep or fgrep is deprecated, but is provided to allow historical applications that rely on them to run unmodified.

..
..
..
..till the end of the page

The following are some practical uses of grep from my own experience  and some sourced from the net.

1. Search file contents

Search for the word PAGE (case sensitive) in the file application.xml;
$grep "PAGE" /opt/tomcat7/webapps.labs/primetest/WEB-INF/configs/application.xml


For case insensitive match use the -i switch as follows;

$grep -i "PAGE" /opt/tomcat7/webapps.labs/primetest/WEB-INF/configs/application.xml

2. Search inside a directory

Search for the word drvierClassName inside the directory META-INF

$ grep -R "driverClassName" META-INF/

You will see result on a separate line preceded by the name of the file in which it was found.

3. Find whole words only

When you search for class, grep will match class, className etc.

$ grep -w "class" WEB-INF/context.xml

4. Multiple word search

Use the egrep command as follows:
$ egrep -w 'word1|word2' /path/to/file

5. Count occurences

The grep can report the number of times that the pattern has been matched for each file using -c (count) switch:

$ grep -R -c "driverClassName" META-INF/

6. Show line numbers

Pass the -n switch to precede each line of output with the number of the line in the text file from which it was obtained:

$ grep -R -n "driverClassName" META-INF/

7. Names of matching files only

Use the -l (list) switch as follows;

$ grep -R -l "driverClassName" META-INF/


8. Grep invert match

You can use -v option to print inverts the match; that is, it matches only those lines that do not contain the given word. For example print all line that do not contain the word bar:

$ grep -v bar /path/to/file

NB: for coloured output (if not on by default) you can add --color=auto to your grep command

Other options:
  • -A x or -B x (where x is a number) --- display “x” lines After or Before the section where the particular word is found.

Friday, June 7, 2013

Periodicaly restart dead process in Linux



The following is (one way of ) how to automaticaly check for and restart a dead process running in a linux host

Part A

/bin/netstat -ln | /bin/grep ":80 " | /usr/bin/wc -l | /bin/awk '{if ($1 == 0) system("/sbin/service httpd restart") }'

This checks if there is any service running on port 80, if not it runs the command to start the service (apache httpd in this example)

Part B
Create a cron job to periodicaly do the above

#monitors the service every 10 minutes
*/10 * * * * /usr/sesame/bash/service_monitor.sh> /dev/null 2>&1


NB: please note the trailing space after the port number


Tested in Redhat|Fedora|CentOS

Monday, January 24, 2011

FFMPEG - Multimedia Tool

FFmpeg is a free software/open source project that produces libraries and programs for handling multimedia data. It ships with Fedora Linux so I naturally took a dive and have never turned back.....

I normaly use it to convert multimedia files from one format to another. Being a command line tool u expect faster execution.

For example
Convert from MP4 to AVI

#ffmpeg -i inputfile.mp4 outfile.avi


To See Supported File Formats
#ffmpeg -formats

You will get output similar to this
FFmpeg version 0.5, Copyright (c) 2000-2009 Fabrice Bellard, et al.
configuration:
libavutil 49.15. 0 / 49.15. 0
libavcodec 52.20. 0 / 52.20. 0
libavformat 52.31. 0 / 52.31. 0
libavdevice 52. 1. 0 / 52. 1. 0
built on Nov 20 2009 15:52:49, gcc: 4.3.2 20081105 (Red Hat 4.3.2-7)
File formats:
E 3g2 3GP2 format
E 3gp 3GP format
DEA wmav1 Windows Media Audio 1
DEA wmav2 Windows Media Audio 2
DEVSD wmv1 Windows Media Video 7
DEVSD wmv2 Windows Media Video 8
D V wmv3 Windows Media Video 9
DES dvbsub DVB subtitles
DES dvdsub DVD subtitles
DEV D dvvideo DV (Digital Video)
D V dxa Feeble Files/ScummVM DXA
D V D eacmv Electronic Arts CMV video
D V D eatgq Electronic Arts TGQ video
D V eatgv Electronic Arts TGV video
D V D eatqi Electronic Arts TQI Video
D V D escape124 Escape 124
.........To mention but a few



Wednesday, September 1, 2010

Fedora 10 - Startup Scripts

1. Startup Script
I have a fedora core box which needs to run different scripts on startup to provide services to other machines.

I found what appears to be the best solution for me, using ntsysv and init.d. Here's how it's done;

1.) make a new file in the /etc/init.d/ directory
2.) add your script to this file with the following lines at the top;
#!/bin/bash
# chkconfig: 345 85 15
# description: of your file

3.) enter this in the shell;
chkconfig --add startup_filename

4.) type ntsysv (instead of using setup>service>etc) - your startup script should now be in the list, checked and ready for action!

5. Confirm by
# service sesamedms-test start


NB: make sure the file is executable


Sample File

#!/bin/bash
# chkconfig: 345 85 15
# description: starts tomcat server

case "$1" in
start) /opt/tomcat/bin/startup.sh ;;
stop) /opt/tomcat/bin/shutdown.sh ;;
restart) /bin/sh $0 stop
/bin/sh $0 start ;;
*) echo "Usage: $0 {start|stop}"
exit 1 ;;
esac