Shell script to generate random files using RANDOM variable

in Categories Tempfile last updated April 10, 2008
#!/bin/bash
# Shell script to generate random file method # 1 
#
# This is a free shell script under GNU GPL version 2.0 or above
#
# Copyright (C) 2005 nixCraft
#
# Feedback/comment/suggestions : http://cyberciti.biz/fb/
 
echo "List of temporary files : "
for i  in 1 2 3 4 5
do
   FILE="/tmp/$(basename $0).$RANDOM.txt"
   echo $FILE # show file name
   > $FILE # create files
done

Shell script to copy all files recursively and upload them to remote FTP server

in Categories Backup, Ftp last updated April 9, 2008
#!/bin/bash
# Shell script to copy all files recursively and upload them to 
# remote FTP server (copy local all directories/tree to remote ftp server)
#
# If you want to use this script in cron then make sure you have
# file pointed by $AUTHFILE (see below) and add lines to it:
# host ftp.mycorp.com
# user myftpuser
# pass mypassword
# 
# This is a free shell script under GNU GPL version 2.0 or above
# Copyright (C) 2005 nixCraft
# Feedback/comment/suggestions : http://cyberciti.biz/fb/
# -------------------------------------------------------------------------
# This script is part of nixCraft shell script collection (NSSC)
# Visit http://bash.cyberciti.biz/ for more information.
# -------------------------------------------------------------------------
 
FTP="/usr/bin/ncftpput"
CMD=""
AUTHFILE="/root/.myupload"
 
if [ -f $AUTHFILE ] ; then 
  # use the file for auth
  CMD="$FTP -m -R -f $AUTHFILE $myf $remotedir $localdir"
else
  echo "*** To terminate at any point hit [ CTRL + C ] ***"
  read -p "Enter ftpserver name : " myf
  read -p "Enter ftp username : " myu
  read -s -p "Enter ftp password : " myp
  echo ""
  read -p "Enter ftp remote directory [/] : " remotedir
  read -p "Enter local directory to upload path [.] : " localdir
  [ "$remotedir" == "" ] && remotedir="/" || :
  [ "$localdir" == "" ] && localdir="." || :
  CMD="$FTP -m -R -u $myu -p $myp $myf $remotedir $localdir"
fi
 
$CMD

Shell script to backup directories from Linux server to Windows 2000/NT Server

in Categories Backup last updated August 5, 2008
#!/bin/bash
# Shell script to backup directories from Linux server to Windows 2000/NT Server. 
# Run it as follows
# Scriptname /home backup abc123 //server2000/backup
# Backup /home directory from Linux box  to NT/2000 box called
# 'server2000' in share called '/backup' with username
# 'backup' and password 'abc123'
# --------------------------------------------------------------------
# This is a free shell script under GNU GPL version 2.0 or above
# Copyright (C) 2005 nixCraft project
# Feedback/comment/suggestions : http://cyberciti.biz/fb/
# -------------------------------------------------------------------------
# This script is part of nixCraft shell script collection (NSSC)
# Visit http://bash.cyberciti.biz/ for more information.
# -------------------------------------------------------------------------
 
# backup what?
FROM=$1
# NT Connection Info #
# NT Username
NTUSER=$2
# NT Password
NTPASSWD=$3
# NT ShareName i.e //server/backup etc
NTSHARE="$4"
 
# BackUpDir Name
BACKDIR="$(hostname -s)"
 
# Local mount point
MNT="/mnt/smbbox"
 
# Get date and time 
NOW=$(date +"%m-%d-%Y-%I_%M%P")
# backup file  name
BAKFILE="backup.$NOW.tar.gz"
 
if [ "$#" != "4" ]; then
	echo "Syntax:"
	echo "$(basename $0) {Linux-directory} {NTusername} {NTpassword} {//NTserver/share-name}"
	exit 1
fi
# make sure $from do exits
if [ ! -d $FROM ]; then
   echo "Backup source directory \"$FROM\" does NOT exist"
   exit 2
fi
#Create tar to backup first
tar -czf /tmp/$BAKFILE $FROM 
 
#Mount the smb to /mnt 
[ ! -d $MNT ] && mkdir -p $MNT || :
 
mount -t smbfs -o username=$NTUSER,password=$NTPASSWD $NTSHARE $MNT
 
[ ! -d $MNT/$BACKDIR ] && mkdir -p $MNT/$BACKDIR || :
 
# Copy new tar to ntbox
cp /tmp/$BAKFILE $MNT/$BACKDIR
 
# Send sync aka force to write data before issuing umount
sync
 
# issue umount
umount $MNT