PyBlosxom |
/Admin/commandLine/misc:
Send E-mail From the Command Line
echo "This will go into the body of the mail." | mail -s "Hello world" you@youremail.comOr, if you wish to send to a remote SMTP server, install the heirloom-mailx package and:
export smtp=host:port
mailx -s "some subject" address@example.com
some random body text
ctrl-D
This also works well in a cron job.
posted at: 21:57 | path: /Admin/commandLine/misc | permanent link to this entry
/Admin/commandLine/misc:
Fingerprint a Public GPG Key
This is particularly interesting in the context of RetroShare[1], and the prevention of Man-In-The-Middle (MITM) attacks:
gpg --with-fingerprint file-containing-public-key.rsc
Both sides of the key exchange should generate a fingerprint for both keys, and then compare the fingerprints over another communication channel (definitely NOT using RetroShare!).
[1] http://retroshare.sourceforge.net/
posted at: 02:42 | path: /Admin/commandLine/misc | permanent link to this entry
/Admin/commandLine/misc:
Resuscitating A Damaged Hard Disk
So my laptop received a pretty hard knock while being turned on, and a part of the disk was destroyed. Having gotten everything I could off the thing (I did not lose anything important) my thoughts now turn to "can I fix it". It is, after all, a newish 500G disk with a non-trivial price tag. Let's try:
First put the thing in a USB enclosure, hook it up, and use your favorite partition editor to divide it into several partitions (I chose five 100G partitions). Then start testing the partitions one by one, with a read/write test, ie.:
e2fsck -k -c -c /dev/sdb1
dumpe2fs -b /dev/sdb1
Remove any partitions that have errors. Then install Debian in the ones that are left, using LVM to stitch them all together. Wish me luck....
posted at: 08:58 | path: /Admin/commandLine/misc | permanent link to this entry
/Admin/commandLine/misc:
Web Page to HTML
Especially when the page runs off the screen and a screenshot just will not do the job:
wkhtmltopdf http://blog.langex.net/ /tmp/webpage.pdf
And really useful for those of us whose primary CV is a web page.
posted at: 02:07 | path: /Admin/commandLine/misc | permanent link to this entry
/Admin/commandLine/misc:
yum: Use Just One Repo to Fix Broken Dependency
Recently seen on Amazon AWS' "Linux" distribution: mosh would not install because of a broken dependency on libprotobuf. This was a soluble problem, because an installable version of mosh existed in the epel repo, but yum insisted on installing the most recent version from the AWS repo, even though it was broken. The fix is to restrict yum to consider only packages from epel, and ignore all other repos:
yum --disablerepo "*" --enablerepo "epel" install protobuf mosh
posted at: 02:33 | path: /Admin/commandLine/misc | permanent link to this entry
/Admin/commandLine/misc:
Processing Lists
Suppose, for instance, you want to remove all i386 packages from an amd64 install:
apt-get remove $(wajig list-installed | grep i386)
posted at: 10:06 | path: /Admin/commandLine/misc | permanent link to this entry
/Admin/commandLine/misc:
Convert Unix/Linux Time to Human-Readable Time
This displays the Unix time in seconds:
$ date +%s
This converts time in seconds 1190000000 to a readable date/time:
$ date -d @1190000000
posted at: 04:00 | path: /Admin/commandLine/misc | permanent link to this entry
/Admin/commandLine/misc:
Logging to the System Log
This is actually more of a scripting thing, but what is a bash script except a collection of command lines....
To send a bit of text to /var/log/syslog:
logger Hello logging world!!
If you wish the output of a particular line in the script to be logged:
mysql -V | logger
will send the MySQL version to syslog. If you wish to also capture errors (STDERR) output, this will do it:
mysql < /path/to/a/sql/script.sql 2>&1 | logger
will send both script and error output to syslog.
posted at: 05:55 | path: /Admin/commandLine/misc | permanent link to this entry
/Admin/commandLine/misc:
User Group Management
To find out what groups a user belongs too:
groups username
The easiest way to add a group to a user:
adduser username groupname
However, this does not work on all Linux distributions (CentOS?). A more general method:
usermod -a -G groupname username
posted at: 22:29 | path: /Admin/commandLine/misc | permanent link to this entry
/Admin/commandLine/misc:
Difficulty Unmounting
When unmounting a partition / device, for example
umount /media/thumb
One might encounter a "busy" error, which indicates some process is still using the partition in question. To perhaps find out who / what is using the partition and do something about it:
lsof | grep '/media/thumb'
And as a last resort, kill all process accessing the partition:
fuser -km /media/thumb
umount /media/thumb
posted at: 06:07 | path: /Admin/commandLine/misc | permanent link to this entry