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

How to Import Customer Records Into OTRS from CSV

Thanks to Mike Dent’s efforts and OTRS, we now know how a CSV file can be imported into the MySQL database directly. Here is the sample code:

mysql> load data infile '/tmp/otrs_test.txt' into table customer_user
fields terminated by '\t' lines terminated by '\r' (first_name,
last_name, address, postcode, phone1, email, customer_id, valid_id,
create_time, create_by, change_time, change_by, login);

Make sure to import all the required fields (that is, the ones that the database requires, see the table schema for details, >show table x;)

Posted under Freeware, MySQL, WebDev

This post was written by Content Curator on November 16, 2009

Tags: , , , , , , , , , , , , , , , , , , ,

Alternate Time Servers for Automatic Clock Set

In modern Microsoft Windows operating systems and all Unix / Linux systems the system clock time can be set automatically. The computer will connect to a special server on the Internet called a Network Time Protocol server, and get the current universal time, and then adjust it according to the local time zone on the computer. It keeps the computer clock very accurate and corrects drift before it can become much of a problem.

We recommend using a reliable server: pool.ntp.org

A wonderful group of generous folks provide this extremely reliable cluster of computers for us all to use, free of charge. Thank you NTP Pool Project and all the participants!

Posted under Freeware, Linux, WebDev

How to automatically reload a page when it is finished reloading, using javascript

So, you have a web page (HTML, PHP, etc.) that you want to reload over and over. And at the same time, you want to be sure that the entire page loads before it starts the loop over again. Here is a javascript way to do just that. Simply include this script in yout HTML code, and watch the magic:

<script language="javascript">
window.onload=new Function("window.location.reload();");
</script>

Enjoy!

Posted under WebDev

This post was written by Content Curator on October 3, 2008

Tags: , , , , , , , , , , , , , ,

Set Windows clock to UTC time

Save the following lines as utc.reg, and then run it to import this registry tweak. It allows you to set the hardware clock in your PC’s BIOS to UTC time. This is handy for boot dual-booting Mac, or Linux, when those operating systems are set to read the BIOS clock as UTC time, instead of Windows’ preferred Local Time (ie. PST, PDT, MST, MDT, CST, CDT, EST, EDT, or the standard “GMT-” and “GMT+“)

Here is the code to save as utc.reg:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\TimeZoneInformation]
“RealTimeIsUniversal”=dword:00000001

Posted under Apple, Linux, Microsoft

This post was written by Content Curator on October 30, 2007

Tags: , , , , , , , , , , , , , , , , ,