UrFix's Blog

A geek without a cause

  • 11 Not Sick Linux Commands

    by

    1) Create a pdf version of a manpage

    man -t manpage | ps2pdf – filename.pdf

    Quick and dirty version. I made a version that checks if a manpage exists (but it’s not a oneliner). You must have ps2pdf and of course Ghostscript installed in your box.

    Enhancements appreciated :-)

    2) Bind a key with a command

    bind -x '"\C-l":ls -l'
    
    
    the -x option is for binding to a shell command

    3) Use file(1) to view device information

    file -s /dev/sd*

    file(1) can print details about certain devices in the /dev/ directory (block devices in this example). This helped me to know at a glance the location and revision of my bootloader, UUIDs, filesystem status, which partitions were primaries / logicals, etc.. without running several commands.

    See also:

    file -s /dev/dm-* file -s /dev/cciss/*etc..

    4) Single use vnc-over-ssh connection

    ssh -f -L 5900:localhost:5900 your.ssh.server "x11vnc -safer -localhost -nopw -once -display :0";
    vinagre localhost:5900
    
    This command

    1. SSH into a machine
    2. Tunnels VNC port to your local computer (“-L 5900:localhost:5900”)
    3. Runs a single use vnc server (“x11vnc -safer -localhost -nopw -once -display :0”)
    4. Goes into the background (“-f”)
    5. Runs VNC viewer on the local computer connecting to the remote machine via the newly created SSH tunnel (“vinagre localhost:5900”)

    
    

    5) Stop Flash from tracking everything you do.

    for i in ~/.adobe ~/.macromedia ; do ( rm $i/ -rf ; ln -s /dev/null $i ) ; done

    Brute force way to block all LSO cookies on a Linux system with the non-free Flash browser plugin. Works just fine for my needs. Enjoy.

    6) A child process which survives the parent’s death (for sure)

    ( command & )

    Test scenario:

    * Open xterm (or konsole, …)

    * Start xeyes with: ( xeyes & )

    * Close the xterminal

    The xeyes process should be still running.

     

    7) Compare copies of a file with md5

    cmp file1 file2

    8) backup delicious bookmarks

    curl --user login:password -o DeliciousBookmarks.xml -O 'https://api.del.icio.us/v1/posts/all'
    
    

    Useful script to backup all your delicious bookmarks. With decilicious shutting down soon , it could be useful

    9) Run a program transparently, but print a stack trace if it fails

    gdb -batch -ex “run” -ex “bt” ${my_program} 2>&1 | grep -v ^”No stack.”$

    For automated unit tests I wanted my program to run normally, but if it crashed, to add a stack trace to the output log. I came up with this command so I wouldn’t have to mess around with core files.

    The one downside is that it does smoosh your program’s stderr and stdout together.

    10) back ssh from firewalled hosts

    ssh -R 5497:127.0.0.1:22 -p 62220 user@public.ip

    host B (you) redirects a modem port (62220) to his local ssh.

    host A is a remote machine (the ones that issues the ssh cmd).

    once connected port 5497 is in listening mode on host B.

    host B just do a

    ssh 127.0.0.1 -p 5497 -l user

    and reaches the remote host’ssh. This can be used also for vnc and so on.

    11) Rename HTML files according to their title tag

    perl -wlne'/title>([^<]+)/i&&rename$ARGV,"$1.html"' *.html
    
    

    The above one-liner could be run against all HTML files in a directory. It renames the HTML files based on the text contained in their title tag. This helped me in a situation where I had a directory containing thousands of HTML documents with meaningless filenames.

  • ISPCP Omega hosting Control Panel Based on VHCS

    by

    “ispCP Omega is a modern hosting Control panel, based on VHCS, that provides continued development.” http://isp-control.net/

    You will need a clean installation of Ubuntu 10.10 before proceeding with the tutorial.

    When installing Ubuntu please use a static IP address and a fully qualified domain name accessible from the internet. e.g. hostaname.domain.com

    1. Download and extract ISPCP from Sorceforge

    cd /usr/local/src

    wget http://sourceforge.net/projects/ispcp/files/ispCP%20Omega/ispCP%20Omega%201.0.7/ispcp-omega-1.0.7.tar.bz2/download

    tar xjvf ispcp-omega-1.0.7.tar.bz2

    cd ispcp-omega-1.0.7

    Click here to find out more!

    2. Now update your system

    aptitude update && aptitude upgrade

    3. ISPCP needs some software installed, we will do this now

    ISPCP’s install script is for Ubuntu 10.04 but works just aswell with 10.10

    cd docs/Ubuntu

    aptitude install $(cat ubuntu-packages-lucid)

    You will be asked to enter a new MySql password

    You will also need to configure Courier as below

    Create web directories -> NO
    Type of mail configuration -> Internet Site
    System mail name should be populated with your hostname
    ProFTPd configuration -> Standalone

    4. Build the system using make

    cd /usr/local/src/ispcp-omega-1.0.7

    make -f Makefile.ubuntu install

    5. Copy all the directories to your system and setup

    cp -Rv /tmp/ispcp/* /

    cd /var/www/ispcp/engine/setup

    perl ispcp-setup

    The setup defaults should be adequate, you will be required to enter your MySQL password.

    6. Clean temporary files

    rm -fR /tmp/ispcp

    After setup completes you should be able to login to your new control panel.

    7. Links

    ISPCP Omega – http://isp-control.net/

  • Back up with time stamp

    by

    My wife is constantly reminding me that “technology will always fail you” and she’s right. Muphy’s law states that if anything can go bad, it will! As far as I can remember I’ve had hard drives die on me, and that is why I always backup everything. On top of backing up everything I always test my backups, if you don’t test your backups it’s sort of like you never did a backup in the first place.
    hard drive
    Creating backups has been a big part of my life.

    here is a script to backup all MySQL Databases to individual files

    for I in $(mysql -p -e 'show databases' -s --skip-column-names);
    do mysqldump -p $I | gzip > "/var/www/mysqlbackups/$I.sql.gz"; done

    Here is a simple one liner to back up everything in your www folder to a mounted hard drive on /mnt/sdb5

    tar zcvf /mnt/sdb5/backups/backup$(date '+%F_%H%I%S%P').tar.gz /var/www  
    
    -z, --gzip "filter the archive through gzip"

    -c, --create "create a new archive"
    -v, --verbose "verbosely list files processed"
    -f, --file=ARCHIVE "use archive file or device ARCHIVE"
    /mnt/sdb5/backups/backup$(date '+%F_%H%I%S%P').tar.gz "location with time stamp"
    /var/www "folder backup"
    combine these 2 one-liners and you have your self a pretty good backup.

    all that’s left to is add the lines to a cron job run the mysql one-liner at 11:30 and run the /var/www backup at midnight.

  • Happy Days

    by

    Happy Days

    echo {'1,2,3',4}" o'clock" ROCK
    
    
    
    
    This never gets old
Chat

Hi 👋, how can we help?