How to Make a Backup Script for Shell in Linux
For those who hack a lot of Linux at the command line interface, backing up files such as config files before editing is a good habit to have. IMHO anyway. So to save time, a little script can be written, chmod +x, and placed into /usr/local/bin or some other that users have in their executable shell PATH. I name mine “bu” to make it easy, and it takes one command line argument which is the filename of the file you want to make a backup copy of. It is called by running something like $ bu myfile
Here’s the code. Comments welcome
The code creates a timecode based on today’s date and the current time to the second, and appends that to the original filename. The a copy is saved with this new “timestamped” backup filename, right in the same directory. Easy-peasy!
#!/bin/bash
OLDFILENAME=$1
DATECODE=$(date +%Y%m%d)
TIMECODE=$(date +%H%M%S)
NEWFILENAME="${OLDFILENAME}_backup${DATECODE}-$TIMECODE"
cp $OLDFILENAME $NEWFILENAME
SUCCESS=$?
if [ $SUCCESS -eq 0 ];then
echo "OK! Copied \"$OLDFILENAME\" to \"$NEWFILENAME\""
else
echo "FAIL! You'll need to try again!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
fi
Posted under Linux
This post was written by kb-admin on April 13, 2010
How To Make puTTY Automatically Load a Session
The most awesome emulator of all time, puTTY.exe, just got even easier to use. Along with loggiong automatically into a SSH session add the Windows shortcut that loads a saved session and launches it, now you have one click shell access to your Linux host from your Windows PC.
Here’s how:
- Download puTTY.exe
- Save it to the folder C:\puTTY\
- Open a Windows Explorer window in C:\puTTY\
- Run puTTY.exe once, and create a “saved session”, making note of what you name it. My example below uses the name my neatly named Saved Session
- Right-click-drag puTTY.exe and drop it next to itself, this creates a shortcut to the .exe file.
- Right-click the shortcut you just created, on the popup menu click Properties.
- In the Target box, add -load “your-saved-session-name” after C:\putty\putty.exe
- The final content in the target box should look like:
C:\putty\putty.exe -load "my neatly named Saved Session"
- Save the shortcut. Viola! Move or copy this shortcut anywhere you like (e.g. your Desktop, your QuickLaunch toolbar, your custom explorer toolbar, etc.) and you have 1-click access to a command prompt on your Linux / Unix host.
Enjoy!
Posted under Apple, Freeware, Linux, Microsoft, Network, Software, WebDev, ZyXel
This post was written by kb-admin on December 5, 2009