"HTTPD dead but PID exists", your disk space is either full or all IPCS semaphores have been used up.
ipcs -s | awk ' $3 == "apache" {print $2, $3}' | awk '{ print $1}' | while read i; do ipcrm sem $i; done
Clean up ipcs semaphores
"What can a one liner do for you?" - Frankly Speaking
ipcs -s | awk ' $3 == "apache" {print $2, $3}' | awk '{ print $1}' | while read i; do ipcrm sem $i; done
Clean up ipcs semaphores
function removeEmptyLines($string)
{
return preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/", "\n", $string);
}
`echo "$clean" | tr A-Z a-z | tr "[]()&~@#$%^&*()_+=;:,.!' " "-" `;
This programming one liner allows you to clean the unwanted characters in a string. The list of characters is specified as the first parameter to the tr command.
str_replace tr
##########################################################
### Find and Replace Script by Frank Mash ###
##########################################################
--> Usage: /sbin/fr [filename] [search] [replace] [b] [i]
--> ################# EXAMPLES #############################
--> EXAMPLE 1: Find 'Apples' and Replace with 'Oranges'. Create a backup of file and proceed in Interactive mode
----> fr /path/to/file.txt Apples Oranges b i
--> EXAMPLE 2: Find 'Apples' and Replace with 'Oranges'. Create a backup of file and proceed in Non-Interactive mode
----> fr /path/to/file.txt Apples Oranges b
--> EXAMPLE 3: Find 'Apples' and Replace with 'Oranges'. Don't create a backup of file and proceed in Non-Interactive mode
----> fr /path/to/file.txt Apples Oranges
--> ################# END EXAMPLES #########################
--> ################# NOTES ################################
----> Currently you cannot proceed in Interactive mode without creating a backup
--> ################# END NOTES ############################
--> You entered: /sbin/fr help
This custom programming one liner allows you to find and replace using one line. E-mail me at softwareengineer99 on Yahoo's e-mail service if you would like the source code.
fr sed grep
awk '/PATTERN/ {print "PATTERN FOUND"}' /var/awk_programming_test
This programming one liner allows you to search for PATTERN in awk_programming_test file. Once the pattern is found, the print statement is invoked .
awk ' BEGIN{FS=",";} { $2= ""; print}' /var/awk_programming_test
This programming one liner allows you to delete the second field in the specified CSV and the results are displayed on the screen. If the file /var/awk_programming_test had the following contents:
redhat,linux web server
fedora,linux web server
xp,windows dedicated server
windows 98,windows dedicated server
solaris,sun web server
redhat
fedora
xp
windows 98
solaris
awk
gcc --version
This programming one liner allows you to find which version of gcc (compiler) is installed on your linux server.
gcc
fuser -l
This programming one liner allows you to output signal names using fuser. Linux signal names are displayed as follows
[root@plain docs]# fuser -l
HUP INT QUIT ILL TRAP ABRT IOT BUS FPE KILL USR1 SEGV USR2 PIPE ALRM TERM
STKFLT CHLD CONT STOP TSTP TTIN TTOU URG XCPU XFSZ VTALRM PROF WINCH IO PWR SYS
UNUSED
fuser
gunzip site*.gz
This programming one liner allows you to unzip / gunzip all files beginning with site and ending with .gz within the current directory
gunzip gzip
If you have unneeded and unexplained ports open on your server, you are calling for trouble.
nmap -p 1-65535 localhost
This programming one liner allows you to look for all open ports (ports that are currently listening) on your Linux server.
nmap fuser
Output of running the above command will produce something similar to:
Starting nmap V. 3.00 ( www.insecure.org/nmap/ )
Interesting ports on localhost.localdomain (127.0.0.1):
(The 65517 ports scanned but not shown below are in state: closed)
Port State Service
21/tcp open ftp
22/tcp open ssh
53/tcp open domain
80/tcp open http
110/tcp open pop-3
143/tcp open imap2
199/tcp open smux
443/tcp open https
631/tcp open ipp
783/tcp open hp-alarm-mgr
953/tcp open rndc
993/tcp open imaps
995/tcp open pop3s
3306/tcp open mysql
5981/tcp open unknown
6001/tcp open X11:1
Nmap run completed -- 1 IP address (1 host up) scanned in 155 seconds
If you are interested in looking up which process is using the port, use the following fuser command. We are investigating port 783 which is currently open for the service named hp-alarm-mgr.
fuser -n tcp 783
783/tcp: 2385
Now that we know the process id (pid), we can find out details about the process.
cat /proc/2385/status
Name: spamd
State: S (sleeping)
Tgid: 2385
Pid: 2385
PPid: 1
TracerPid: 0
Uid: 0 0 0 0
Gid: 0 0 0 0
FDSize: 32
Groups:
VmSize: 22920 kB
VmLck: 0 kB
VmRSS: 716 kB
VmData: 16664 kB
VmStk: 72 kB
VmExe: 12 kB
VmLib: 3944 kB
SigPnd: 0000000000000000
ShdPnd: 0000000000000000
SigBlk: 0000000000000000
SigIgn: 0000000000010080
SigCgt: 0000000080005002
CapInh: 0000000000000000
CapPrm: 00000000fffffeff
CapEff: 00000000fffffeff
We can see the software package running the process is spamd and its owned by uid 0 (super user).
The status information will include a lot of details about the process.
To find further details, such as the command used to invoke the process:
ps 2385
PID TTY STAT TIME COMMAND
2385 ? S 0:00 /usr/bin/spamd -d -c -a
nmap fuser cat
date >> /user/security/ssh-intruders.log ; cat /var/log/messages* | grep -i "sshd.*authentication failure" | sort | awk '{FS="rhost="; print $2}' | awk '{FS="user="; print $1}' | grep ".*\..*\." | grep -v "knownhost.com" | grep -v "knownhost2.com" | sort | uniq | while read i; do counter=`grep -i "$i" /var/log/messages* | wc -l` ; echo "$counter attempts by $i"; done >> /user/security/ssh-intruders.log ; cat /user/security/ssh-intruders.log
This programming one liner allows you to query /var/log/messages files for break-in attempts. Prints the total count of attempts by each intruder.
The following output (sample) is produced
3 attempts by 163.27.207.193
2 attempts by 84.243.73.25
14 attempts by ali.2kads.cz
17 attempts by c66.110.175-222.clta.globetrotter.net
9 attempts by pro-177.im.cju.edu.tw
9 attempts by pro-177.im.cju.edu.tw
cat awk sed sort uniq wc date
[root@plain home]# rpm -qip gnome-desktop-2.2.2-2.2E.src.rpm
Name : gnome-desktop Relocations: (not relocatable)
Version : 2.2.2 Vendor: Red Hat, Inc.
Release : 2.2E Build Date: Wed 20 Jul 2005 04:12:27 PM CDT
Install Date: (not installed) Build Host: crowe.devel.redhat.com
Group : System Environment/Libraries Source RPM: (none)
Size : 1081813 License: GPL
Signature : DSA/SHA1, Wed 10 Aug 2005 03:04:49 AM CDT, Key ID 219180cddb42a60e
Packager : Red Hat, Inc.
URL : http://www.gnome.org
Summary : Package containing code shared among gnome-panel, gnome-session, nautilus, etc.
Description :
The gnome-desktop package contains an internal library
(libgnomedesktop) used to implement some portions of the GNOME
desktop, and also some data files and other shared components of the
GNOME user environment.
This programming one liner allows you to display RPM (Red Hat package manager) information.
rpm
Options used
-q = query
-i = information
-p = packages
wall
This programming one liner allows you to everyone connected to a terminal. Simply type wall, enter the message and press Ctrl-d to send it.
[root@plain user]# wall
fixed
Broadcast message from root (pts/0) (Sat Oct 29 22:52:36 2005):
fixed
wall
tar -Wcvf /user/backups/site6-fst.tar etc home var >/designerz/backups/log.site6.fst.bk
This programming one liner allows you to create a verified archive. The command generates all files processed to the screen.
tar
ps 316
For a currently running process, you can use ps with the process id (pid) to see information about the process and to verify that its still running.
ps
[root@plain html]# ps
PID TTY TIME CMD
20056 pts/5 00:00:05 bash
316 pts/5 00:07:53 tar
3302 pts/5 00:00:00 ps
rsync -vrplogDtH /olda/dir /home/dir
This programming one liner allows you to restore / copy files from one hard drive to another. This can be useful in cases when you have a hacked hard drive as slave attached to your web server and now you want to restore files.
rsync rcpBrief explanation of options used with rsync for restoring files between hard drives.
-v, --verbose increase verbosity
-r, --recursive recurse into directories
-p, --perms preserve permissions
-l, --links copy symlinks as symlinks
-o, --owner preserve owner (root only)
-g, --group preserve group
-D, --devices preserve devices (root only)
-t, --times preserve times
-H, --hard-links preserve hard links
This programming one liner allows you to see what files and directories are available within a folder on your Linux web server. Upon invocation of this one liner, the contents of your current directory (pwd) will be displayed.
ls
If you believe your ls binary is corrupt (due to a server hack) or just to use an alternate command, you can use the following command on Linux server to get the same results. dir and ls are infact two different binaries.
dir
The following one liner will let you view detailed information about files and directories within your present directory. This command is commonly termed as "long listing format".
ls -l
Similarly, you can use the long listing option with dir command.
dir -l
This command can be used to view the listings with color codings (if supported by your Linux web server).
ls --color=tty
To make the color coded listings part of your profile, simply add the following lines to your .bash_profile directory. You can also execute this command to just color code the listings for your current session.
alias ls='ls --color=tty'
ls dir
du -h -s site6-www.tar.defunct
This programming one liner allows you to view total disk used by a folder or file on a server in a summarized and readable format.
df du
rm -r -f /tmp/directory
This programming one liner allows you to recursively, completely and forcefully remove the directory.
rm unlink
cd /user/backups; ls -1 /oldb2/home/virtual/ | grep site | grep -v '-' | while read i; do bkdir=/oldb2/home/virtual/$i; echo $i; echo $bkdir; tar -cf $i-www.tar $bkdir/fst/var/www; echo "Gunzip $i"; gzip $i-www.tar; ls -l $i-www.tar.gz; done
This programming one liner allows you to backup directories. First it makes a tarball of a directory and then uses gzip to compress the tarballs.
ls, grep, tar, ls, gzip