Archive for the ‘bash’ Category

Standard input (STDIN) – keyboard by default
Standard output (STDOUT) – terminal window by default
Standard error (STDERR) – terminal window by default
> Redirect STDOUT to file
2> Redirect STDERR to file
&> Redirect all output to file
2>&1: Redirects STDERR to STDOUT
(): Combines STDOUTs of multiple programs
$ ( cal 2007 ; cal 2008 ) | less

Ever want to immediatly serve content from a specific directory over HTTP, but didn’t want to bother messing with
httpd.conf or other webserver configiurations?

If you’ve got Python installed, this is a snap. Execute python with the SimpleHTTPServer module, using port 8080 so
there isn’t a need to elevate privs to root.

$ python -m SimpleHTTPServer 8080
Serving HTTP on 0.0.0.0 port 8080 …

Sure enough, pointing a browser to the IP address :8080 of the box hits my home directory listing. Super easy, super
fast, super simple!

I use this to serve content to my PS3. The PS3 doesn’t support NFS or CIFS, so to download content to the hard drive,
the best method is by pulling it over HTTP with the embedded web brower. On my MacBook, I change into the directory
containing whatever media I want to transfer, fire up HTTP, and suck it down to the hard drive on the PS3. Nice!

source: http://prefetch.net/blog/index.php/2009/10/31/serve-out-content-over-http-from-your-cwd-immediatly/

Full list of available commands    Ctrl-a Ctrl-?
Open a new screen in existing session    Ctrl-a Ctrl-c
Switch to last accessed screen    Ctrl-a Ctrl-a
Switch to next screen    Ctrl-a Ctrl-n
Switch to previous screens    Ctrl-a Ctrl-p
Disconnect, leaving the session running in background    Ctrl-a Ctrl-d
Split screen vertically    Ctrl-a Ctrl-S
Unsplit screen    Ctrl-a Ctrl-Q
Move focus between splits    Ctrl-a Ctrl-Tab
List currently opened screens    Ctrl-a Ctrl-S
Rename current screen    Ctrl-a Ctrl-A
Monitor a screen for silence    Ctrl-a Ctrl-_
To disconnect (but leave the session running)
Hit Ctrl + A and then Ctrl + D in immediate succession. You will see the message [detached]
To reconnect to an already running session
screen -r
To reconnect to an existing session, or create a new one if none exists
screen -D -r
To create a new window inside of a running screen session
Hit Ctrl + A and then C in immediate succession. You will see a new prompt.
To switch from one screen window to another
Hit Ctrl + A and then Ctrl + A in immediate succession.
To list open screen windows
Hit Ctrl + A and then W in immediate succession

$ cat /etc/passwd | awk -F: '{print $1}' | while read line; do echo $line; crontab -l -u $line; done

http://www.linuxscrew.com/2009/12/21/best-of-linux-cheat-sheets/

tar cf file.tar files – create a tar named file.tar containing files
tar xf file.tar – extract the files from file.tar
tar czf file.tar.gz files – create a tar with Gzip compression
tar xzf file.tar.gz – extract a tar using Gzip
tar cjf file.tar.bz2 – create a tar with Bzip2 compression
tar xjf file.tar.bz2 – extract a tar using Bzip2
gzip file – compresses file and renames it to file.gz
gzip -d file.gz – decompresses file.gz back to file

SELECT accounts.id, mail.mail_name, accounts.password, domains.name FROM domains LEFT JOIN mail ON domains.id = mail.dom_id LEFT JOIN accounts ON mail.account_id = accounts.id

Ever want to immediatly serve content from a specific directory over HTTP, but didn’t want to bother messing with
httpd.conf or other webserver configiurations?

If you’ve got Python installed, this is a snap. Execute python with the SimpleHTTPServer module, using port 8080 so
there isn’t a need to elevate privs to root.

$ python -m SimpleHTTPServer 8080
Serving HTTP on 0.0.0.0 port 8080 …

Sure enough, pointing a browser to the IP address :8080 of the box hits my home directory listing. Super easy, super
fast, super simple!

I use this to serve content to my PS3. The PS3 doesn’t support NFS or CIFS, so to download content to the hard drive,
the best method is by pulling it over HTTP with the embedded web brower. On my MacBook, I change into the directory
containing whatever media I want to transfer, fire up HTTP, and suck it down to the hard drive on the PS3. Nice!

source: http://prefetch.net/blog/index.php/2009/10/31/serve-out-content-over-http-from-your-cwd-immediatly/

c ~ $ strace -f -s 128 $(pidof httpd |sed 's/\([0-9]*\)/\-p \1/g')

Quite simple really, just use sed to make the necessary command line switches.

strace wants to have the PIDs passed one per '-p' switch. It would be nice to have a -p 3434,4565,4342 option but oh
well. sed with a easy replace handles all that's necessary.

Observe the output of pidof

c ~ $ pidof httpd
9629 9439 9428 9427 9426 9425 9424 9420

Wrap with sed to create multiple -p switches.

c ~ $ pidof httpd |sed 's/\([0-9]*\)/\-p \1/g'
-p 9629 -p 9439 -p 9428 -p 9427 -p 9426 -p 9425 -p 9424 -p 9420

Now combine with strace.

c ~ $ strace $(pidof httpd |sed 's/\([0-9]*\)/\-p \1/g')
carbon share # strace $(pidof apache2 |sed 's/\([0-9]*\)/\-p \1/g')
Process 9629 attached - interrupt to quit
Process 9439 attached - interrupt to quit
Process 9428 attached - interrupt to quit
Process 9427 attached - interrupt to quit
Process 9426 attached - interrupt to quit
Process 9425 attached - interrupt to quit
Process 9424 attached - interrupt to quit
Process 9420 attached - interrupt to quit
[pid 9439] semop(10846209, 0xb7bd9a28, 1
[pid 9629] semop(10846209, 0xb7bd9a28, 1
[pid 9428] epoll_wait(10,
[pid 9427] semop(10846209, 0xb7bd9a28, 1
[pid 9426] semop(10846209, 0xb7bd9a28, 1
[pid 9424] semop(10846209, 0xb7bd9a28, 1
[pid 9420] select(0, NULL, NULL, NULL, {0, 730000}
[pid 9425] semop(10846209, 0xb7bd9a28, 1
[pid 9420] <... select resumed> ) = 0 (Timeout)
[pid 9420] waitpid(-1, 0xbff91918, WNOHANG|WSTOPPED) = 0
[pid 9420] select(0, NULL, NULL, NULL, {1, 0}) = 0 (Timeout)

Now go debug some PHP or CGI application in the guts

Source: http://edoceo.com/exemplar/strace-multiple-processes

LDAP server is not responding, database looks corrupted.
Article ID: 5476
Last Review: Feb,9 2009
Author: Vitaly Filatov
Last updated by: Vitaly Filatov APPLIES TO:

* Parallels Operations Automation

Symptoms
LDAP server can be started, but it is not listening on port 389 and is not working, ‘slapcat’ hangs too.
Cause
LDAP back-end database is corrupted.
Resolution
Use slapd_db_recover to recover the database, for example:
[root@psaldap ldap]# slapd_db_recover -v -h /var/lib/ldap
db_recover: Finding last valid log LSN: file: 1 offset 263805
db_recover: Recovery starting from [1][261683]
db_recover: Recovery complete at Thu Jul 17 08:29:23 2008
db_recover: Maximum transaction ID 80000175 Recovery checkpoint [1][264861]

WARNING: Always backup database files before working the database, for standard install files are located in
/var/lib/ldap