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 Delete Returns in Excel

The pesky carraige return and new line characters, while providing a way to present text for human viewing, are not always desirable when working in a spreadsheet program like Microsoft Excel or OpenOffice.org.

In Excel, a bit of code provided by Ivan Moala on mrexcel.com, works wonders. Here is the code:


'Created by Chip Pearson
'Cleans up data by removing tabs and carriage returns in worksheet cells.
Sub CleanUp()
Dim TheCell As Range
For Each TheCell In ActiveSheet.UsedRange
With TheCell
If .HasFormula = False Then
.Value = Application.WorksheetFunction.Clean(.Value)
End If
End With
Next TheCell
End Sub

Here’s how to use it:

  • In Excel click Tools > Macro > Visual Basic Editor (or just hit Alt-F11)
  • In the top-left pane under the Project heading, double-click the name of the sheet you want to strip all the newlines and carriage returns from.
  • In the window that pops up, paste the code above into the empty box under where you see General and Declarations.
  • Run the macro by clicking the “play” button above, or hit F5

Warning: make a backup copy of your Excel workbook before performing the above procedure.

Posted under Excel, Microsoft, Uncategorized

How to Show MySQL Warnings at CLI

When logged in to the MySQL server using the command line interface (CLI) the  generated errors on the previously run command.

mysql> show warnings;

Thanks to Trevor Nichols and www.issociate.de

Posted under Freeware, MySQL

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

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

Fix 403 Forbidden error in OTRS/Apache

This applies to (at least) OTRS 2.2 on Fedora Core 6 running Apache 2:

To fix this, change the following in the file /etc/httpd/conf.c/otrs.conf
Find the line that reads “Deny from All”, and comment it out by placing a # at the beginning of the line.

Save the file.

Restart Apache

# service httpd restart

Now try browsing your webserver otrs from other machines, success!

Posted under Linux, WebDev

This post was written by Content Curator on December 4, 2007

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

How to Update Firefox on Fedora Core Linux

Using the yum command line usility:

yum -y –enablerepo=development update firefox

(there are two dashes preceding “enablerepo”)

When I used this line I got some transaction check failures thet looked something like:

file /usr/share/pkgconfig/gnome-doc-utils.pc from install of gnome-doc-utils-stylesheets-0.12.0-1.fc8 conflicts with file from package gnome-doc-utils-0.8.0-2.fc6

To fix this, I did the following:

yum -y –enablerepo=development update gnome-doc-utils

This updated the necessary packages, then I re-ran:

yum -y –enablerepo=development update firefox

Success!

Posted under Browsers, Freeware, Linux

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

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

MySQL login with command line (CLI)

# mysql -h hostname -u username -p

It will prompt you for the password.

Then:

> connect dbname

Posted under MySQL

This post was written by Content Curator on September 17, 2007

Tags: , , , , , , , ,

Set time at command line in Linux

This works for all Linux flavors as far as I know:

The date command is used to set the system clock using the switch -s and the format MMDDhhmmYYYY (where MM=month, DD=day, hh=24-hour hour, mm=minute, YYYY=year)

The following example sets the date to January 5th 2007, 1:15 PM:

# date -s 010513152007

Posted under Linux

This post was written by Content Curator on March 9, 2007

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