Shell Script

Stop Recording Bash History

Here's a script based on the information at http://www.cyberciti.biz/tips/shell-root-user-check-script.html.

It erases your history, and then tries to alter /etc/profile to stop recording history for everyone. Run it as a user and as root for the full effect.

nohup - runs your programs after you log out

The following command will run the script, and then keep running the script after you log out.

nohup ./somescript.sh &

How to Backup MySQL on a Website

Usually, a web host will give you FTP access to a directory and a web interface. A button in the web interface will produce a .ZIP file with the database contents, and you can download it via FTP.

Kindle Tricks (Linux)

An Amazon press release said that they sold more Kindle books than paper books. That might be true, but, they probably included the thousands of books being sold for free, or a few dollars. There are numerous public domain books "for sale" on Kindle. I downloaded several dozen.

Here are a few Amazon Kindle tricks.

Installing Skype Dynamic on Linux AMD64

It's pretty simple to set up Skype (dynamic) on Ubuntu 9.10 (beta). I think all the 32bit libraries are installed by default. If they aren't, check out Daryl Dawkins' page about running it on Fedora.

The one oddity I experienced is that you need to run the skype program from within the skype directory. The following script does that - my Skype is installed in ~/bin, my personal bin folder.

Restarting WiFi on OpenWRT if the Link Goes Away

I put my WRT54G into a noisy electrical environment, and it seems to cause the wifi to fade out a couple times a week, sometimes permanently. (I did this after using a USB adapter on Windows proved too unstable.)

After some experimentation, this script below seems to do a reasonable job of keeping it up. Save it, and put it into the crontab. (You have to install the crond package.) The gateway is at 192.168.1.254.

#! /bin/sh

# Checks if the wifi conn is up.  If not, it tries to restart
# the wifi.  If that fails, then reboot.

if ping -c 1 192.168.1.254 > /dev/null
then
        echo nothing > /dev/null
else
        ifdown wifi
        ifup wifi
        killall wifi
        wifi
        /etc/init.d/S41wpa
        sleep 30

Novice's Notebook

This is a repository of "novice" articles, written with the intent of driving more traffic to the site, and getting more ad clicks. It's pretty crass, I know, but the information may be very useful.

OpenWRT Router IP Exposure Script

If you have an OpenWRT router (any router that can run the software can be converted), you can do a little quasi-dynamic-DNS trick. This is useful if you don't really care enough to set up Dyn DNS, and you have a web server setup.

The main disadvantage is that you don't have a DNS record. The main advantage is that the updates don't need to propagate through DNS, so if you have an app that relies on talking to your LAN, you can quickly detect any changes.

First, save this as /usr/bin/checkmyip

#!/bin/sh

past_ip="first"
[ -f /tmp/myip ] &current_ip=`ifconfig | grep P-t-P | tr ':' ' ' | awk '{print $3;}'`

if [ ${past_ip} != ${current_ip} ] ; then
exec wget -q -O /tmp/myip.html http://yourdomain.com/networkname/wrt.php?ip=${current_ip} 2>&1 &

Set UID C fragment

I'll be getting back to the regular code in a bit. For now, here's a tiny code fragment I'm using, now recorded here for posterity. I'm in a little shock - this is the only C code I use anymore.

Sometimes, you need to run a script as root. This is a little bit of C code that does that. The program compiles, and you chmod it to setuid, and chown it root.

#define SCRIPT "/usr/local/buildserver/setup_web"
main(argc, argv)
char **argv;
{
    setuid(0);
    seteuid(0);
    execv(SCRIPT, argv);
}

Yikes! I didn't know I still had old K&R C lying around. I thought that went out of fashion at the same time as Michael Jackson's "Bad" album.

The main() should be: main(int argc, char *argv[])

It's also uncool to pass argv to the script. Setuid proxies can filter the arguments so that the script exposes a limited interface to root. Maybe this library could help impose some order.

.


Syndicate content