Daily Archives: June 12, 2010

screen

screen
Got a shell connection to a dodgy host that keeps giving you the boot? after you login, run screen:
#screen -DD -R

You will still get booted, but at least you can get right back to where you were when you reconnect by replaying the above command.

tar

tar
good old tape archive.
To extract:
#tar -xvvf filename.tar.gz
To archive:
# tar -czvf tarballname.tar.gz directory

wget

wget
use wget to grab that tarball directly, for when you are grabbing such things off sourceforge or wherever.
# wget http://domain.com/pathtofile.tar.gz

crontab

crontab
A crontab line should point to a .sh script. The .sh script can then execute the shell script. This enables you to use either the sleep funciton or looping constructs to run the script a multiple of times if you like, and  keeps your command to one line inside the cron.
Look at your crontab with #crontab -l edit it with #crontab -e
Crontab time examples:|
1 */3 * * *  every 3 hours, one minute after the hour. Where possible, dont run a crontab exactly on the hour, because that is when everybody else does it on a shared host. Set it for a minute after when the cpu isnt likely to be so taxed.
1 0,12 * * * every 12 hours, one minute after the hour.
*/1 * * 3/6 every minute on every third and sixth day of the week

mysql

mysql
Export a db
#mysqldump -uuser -ppassword -hlocalhost dbname > db.sql
Import a db
#mysql -uuser -ppassword -hlocalhost dbname < db.sql

you probably know mysql command line access if you are on this page. You have to know how to work with this because a database can exceed the size allowable for transfer over http, making into phpMyAdmin impossible. But a goodie that I found is that case when you want to wipe out all the tables in a db, but not the db itself, in order to preserve all the privleges, and access credentials. The following line can save a step:
#mysqldump -uuser -ppassword –add-drop-table –no-data dbname | grep ^DROP | mysql -uuser -ppassword dbname