• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Stupid Bash tricks.

drag

Elite Member
I am curious about simple scripts and one liners that people use to make their life easier in Linux/Unix. Of course other shells are welcome.

Here are some examples I use.

#!/bin/bash
# name: ~/bin/backgrd

for i in `ls ~/background/` ; do xsetbg -fullscreen ~/background/$i ; sleep 5m ; done

exec ~/bin/backgrd
#done

This is my backround script I used when I use simple window managers. It is executed from the .xinitrc script (~/bin/backgrd &). It cycles thru the backgrounds I have in a folder. A new one is displayed every 5 minutes. However it doesn't work in Gnome, because it has it's own too-complicated-weirdness.

_____________

#!/bin/bash

for i in `$1`
do
$2 $3 $i $4
done

This one I don't use a whole lot, but was just made to see if I could figure out a simple way to do it. I was doing a lot of loops for dealing with a large number of files. The filename is "fin" and it is in my ~/bin file which I added to my PATH variable.

Say I downloaded a bunch of maps for quake and I need to unzip them. But I don't want to type it out 30-40 times and sit there staring at it until it gets done. So if it's in one folder all I have to do is:

fin ls unzip -o

That is equivilent of typing out: for i in "ls" ; do unzip -o $i ; done]

Pretty stupid eh?

_____________________________

#! /bin/bash

if mount /cdrom
then
echo "ok"
else
eject cdrom
fi

This is named mountlink. Every command has a return value. If it returns 0 then it worked. It will return some other value if it failed then it will return some other values, most of the time 1. This return value is stored in a variable ?. You can see what it returned by "echo $?".

If you do a "if command; then whatever; fi" that tests the return value and if it worked then it would execute what is indicated by the "then".

This command I put into a icon on my taskbar(using gnome right now). I click the icon and if the cdrom is mounted then it umounts and ejects it. If it is not mounted and there is no cd, it will open the tray for me. If there is a mountable cdrom then it mounts it, gnome detects the newly mounted file and has the icon manager put a cdrom icon on my desktop.

If a programmer tried to make a program in C to do that it would take him a long time and several thousand lines of code. And it probably be buggy anyways. This took me a couple minutes to make.

This is my favorite script and I use it the most out of any others I've made.

________________________________

#! /bin/bash

if grep 1 ~/bin/xawtv.lock
then
killall xawtv
amixer sset Line mute
echo "0" > ~/bin/xawtv.lock
else
amixer sset Line unmute
xawtv &
echo "1" > ~/bin/xawtv.lock
fi


This is along the same lines as the the mountlink script. This is named xawtvstart. My TV card is a cheaper model that uses a line in line instead of creating a new sound device so xawtv can't control the input volume. Other TV programs can do this, but xawtv is all I need, and It does everything I want when it comes to watching TV.

It uses a lock-file. Basicly if it finds a "1" in the lock file it will kill xawtv and mute line-in. Then it would put a zero in the lock file. If the lockfile only has a zero it it will unmute the line-in and start xawtv. Then put a 1 in the lock file.

I put this on a icon in my taskbar. Saves me like eight clicks with the mouse each time I want to start watching TV. 🙂
 
cleanmp3s.sh:
#!/bin/sh

rename 'y/A-Z/a-z/' *3
/bin/ls -1 *3 | while read i
do
id3v2 -D "$i" > /dev/null
chown death:death "$i"
chmod 644 "$i"

echo -n "done with: "
/bin/ls -l "$i"
done

That, along with a couple shell aliases, and rename(1), makes organizing mp3s a snap. example

A long time ago I used this to filter out nimda people. It appended iptables rules to a file which was sourced by my main iptables script.

#!/bin/bash
NL=400
IPTABLES=/sbin/iptables
IPTABLESSCRIPT=/etc/rc.iptables.deny
IPTABLESINIT=/etc/init.d/firewaller
tail -n${NL} /var/log/apache/access.log | grep -i 'root.exe' > /tmp/nimdascript.txt

if [ ! -e $IPTABLESSCRIPT ]
then
touch $IPTABLESSCRIPT
chmod o+x $IPTABLESSCRIPT
echo "#!/bin/sh" > $IPTABLESSCRIPT
fi

while read I
do
IP=`echo $I | awk '{print $1}'`
IP=`host ${IP} | awk '{print $3}'`

if [ `cat $IPTABLESSCRIPT | grep ${IP} | awk '{print $7}'` == $IP ]
then
echo "repeat offender $IP"
else
echo "$IPTABLES -A INPUT -p TCP -s ${IP} --dport 80 -j DROP" >> $IPTABLESSCRIPT
fi
done < /tmp/nimdascript.txt

$IPTABLESINIT restart

To take a screenshot and copy it to all the right places (~/images/screens and http://incise.org/images/screenshots ) I use this:

#!/bin/sh

dir=&quot;/tmp/${RANDOM}-screenshot-&quot;`date`

mkdir &quot;$dir&quot;

cd &quot;$dir&quot;

scrot -q 9

rename 's/_[0-9]+x[0-9]+_scrot//' *png

cp *png $HOME/images/screens/

scp *png fw:/var/www/images/screenshots/

cd ~

rm -r &quot;$dir&quot;

To get the weather I run this:

( lynx --dump &quot;http://www.w3.weather.com/weather/local/52806&quot; | grep -A 1 -B 1 &quot;Feels Like&quot; | sed -e &quot;s/Feels Like//&quot; | sed -e &quot;s/\[.*\]//&quot; | sed -e &quot;s/[^a-zA-Z0-9]//g&quot; ) 2>/dev/null

For simple and non-disgusting-looking xmessages I run this (usage: ./foo message)

#!/bin/bash

xmessage -fn &quot;-adobe-helvetica-bold-r-normal-*-*-180-*-*-p-*-iso10646-1&quot; \
-bg &quot;black&quot; -fg &quot;orange&quot; -timeout &quot;2&quot; -buttons &quot;&quot; \
-title &quot;xmessagemp3&quot; -geom x42 -center \
&quot; $1 &quot;

To email a 5 day forecast to my cell phone every morning before I wake up, I have a cron job that runs this at 6am everyday (this one's nasty!):

#!/bin/sh
lynx --dump http://www.w3.weather.com/weather/local/52806 |
egrep -A 24 '\]Today' |
sed -e 's/^.*\[.*\]//g' |
grep -v '%' |
perl -pe 's/^\s+$//g' |
sed -e 's,\d*[^\d]/.*$,,g' |
perl -pe 's/\n/ - /g' |
sed -e 's/ - / /g' |
perl -pe 's/ - /\n/g' |
perl -pe 's/ +/ /g' |
sed -e 's/Today //g' |
sed -e 's/^/* /g' |
mail foo@bar.com

I have others of course, but they're either totally trivial or way too big to put here.

Oh, here's my shell init files, which I am somewhat proud of. 🙂 I use bash but I made them totally compatible with other bourne shells. I also made it so that I can use the same one on both linux and netbsd and everything will work how I want.

.bash_profile
umask 022

PATH=\
$HOME/sw/bin:\
/usr/local/bin:\
/usr/local/sbin:\
/bin:\
/sbin:\
/usr/bin:\
/usr/sbin:\
/usr/X11R6/bin:\
/usr/games

EDITOR=vim
VISUAL=${EDITOR}
EXINIT='set autoindent'
PAGER=less
CVS_RSH=ssh
MAIL=/var/mail/$USER
PYTHONSTARTUP=&quot;$HOME/.pythonstartup.py&quot;
PYTHONPATH=/home/death/sw/lib/python2.2/site-packages
CDR_DEVICE=0,0,0
CDR_SPEED=32

export PATH
export EDITOR
export VISUAL
export EXINIT
export PAGER
export CVS_RSH
export MAIL
export PYTHONSTARTUP
export PYTHONPATH
export CDR_DEVICE
export CDR_SPEED

if [ -x /usr/local/kahakai/bin/kahakai ]
then
PATH=/usr/local/kahakai/bin:$PATH
export PATH
fi

if [ `uname` = &quot;NetBSD&quot; ]
then

PATH=/usr/pkg/bin:/usr/pkg/sbin:/usr/pkg/games:$PATH
export PATH

if [ -x `which sudo` ]
then
sudo mixerctl -n -w inputs.dac.mute=off
sudo mixerctl -n -w outputs.master.mute=off
fi

fi

if [ -x `which sudo` -a -x `which aumix` ]
then
sudo aumix -q -v 80 -c 0 -i 0 -l 0 -p 0 -w 80 -1 0 -2 0 -3 0 > /dev/null 2>&1
fi

if [ -r $HOME/.bashrc ]
then
. $HOME/.bashrc
fi

.bashrc:

if [ &quot;x$BASH&quot; != &quot;x&quot; ]
then
PS1=&quot;${USER}@`hostname` \w % &quot;
else
PS1=&quot;${USER}@`hostname` % &quot;
fi

export PS1

alias more=less
alias ls='ls -F'

if [ &quot;x$EDITOR&quot; = &quot;x&quot; ]
then
alias vi=vim
else
alias vi=$EDITOR
fi

alias weather=$HOME/scripts/weather.sh
alias CleanMp3s=$HOME/scripts/cleanmp3s.sh
alias Lower='rename &quot;y/A-Z/a-z/&quot; *3'

if [ -r $HOME/.bash_keychain_and_TERM.sh ]
then
. $HOME/.bash_keychain_and_TERM.sh
fi

if [ &quot;x$TERM&quot; = &quot;xxterm&quot; ]
then
pts=`tty | tr -d '/dev'`
echo -ne &quot;\033]0;${pts}\007&quot;
fi

set -o vi
 
I used to make little scripts for stuff, but I keep forgetting what I call them and spend more time finding them than it would take me to just type the stuff in them, so Im not using any these days 🙂

Just have a few aliases for a few little things.
 
Originally posted by: Sunner
I used to make little scripts for stuff, but I keep forgetting what I call them and spend more time finding them than it would take me to just type the stuff in them, so Im not using any these days 🙂

Just have a few aliases for a few little things.

alias and bash one liners count. They don't need to be a script!

So what you use?


Here's my .bashrc file:

# /etc/skel/.bashrc:
#Drag's Bash startup settings for interactive situations.

# colors for ls, etc.
alias lss="ls -al --color=auto"
alias ls="ls --color=auto"



#consule colors!
RED="\[\033[0;31m\]"
LRED="\[\033[1;31m\]"
GRN="\[\033[0;32m\]"
LGRN="\[\033[1;32m\]"
BLU="\[\033[0;34m\]"
LBLU="\[\033[1;34m\]"
PUR="\[\033[0;35m\]"
LPUR="\[\033[1;35m\]"
CYA="\[\033[0;36m\]"
LCYA="\[\033[1;36m\]"
YEL="\[\033[0;33m\]"
LYEL="\[\033[1;33m\]"
BRN="\[\033[0;33m\]"
GRY="\[\033[1;30m\]"
LGRY="\[\033[0;37m\]"
WHT="\[\033[1;37m\]"
NON="\[\033[0m\]"

# backgroundcolors
BGRY="\[\033[40m\]"
BRED="\[\033[41m\]"
BGRN="\[\033[42m\]"
BYEL="\[\033[43m\]"
BBLU="\[\033[44m\]"
BPUR="\[\033[45m\]"
BCYA="\[\033[46m\]"
BWHT="\[\033[47m\]"

# Things BASH understands:
# \a an ASCII bell character (07)
# \d the date in "Weekday Month Date" format
# \e an ASCII escape character (033)
# \h the hostname up to the first `.'
# \H the hostname
# \j the number of jobs currently managed by the shell
# \l the basename of the shell's terminal device
# \n newline

# \r carriage return
# \t the current time in 24-hour HH:MM:SS format
# \T the current time in 12-hour HH:MM:SS format
# \@ the current time in 12-hour am/pm format
# \u the username of the current user
# \v the version of bash (e.g., 2.00)
# \V the release of bash, version + patchlevel
# \w the current working directory
# \W the basename of the current working dir
# \! the history number of this command
# \# the command number of this command
# \$ if the effective UID is 0, a #, otherwise a $
# \\ a backslash

PS1="\n-{$RED\u$LGRN@$GRN\h$NON}-$PUR \t$GRN\n$BRED\w >:$NON "
export PS1


I ripped some of the variables of off a website. This is to make my purdy and informative bash prompt.
(note to copy and paste in X you simply highlight what you want to copy and then middle click it were you want to paste.. types it out just like you would if you did it manually.)
 
Still don't have alot of interesting stuff...
PS1='\u@\h: \w> '
alias x86acc='export ACCEPT_KEYWORDS=~x86'
alias x86unacc='unset ACCEPT_KEYWORDS'
alias search='emerge search'
And a bunch of commands that only affect inhouse stuff.

Oh and I can't stand color ls, so I don't have any of that 😉
 
I usually have a ~/admin directory for little scripts and whatnot I write. Helps me keep them "organized" and in a central location. I don't have any of interrest though 😉
 
alias d="ls --color"
alias ls="ls --color=auto"
alias ll="ls --color -l"
alias la="ls --color -la"
alias cp="cp -v"
alias mv="mv -v"
alias rm="rm -v"
alias mozilla="MozillaFirebird"
alias df="df -h"
alias burntemp="cdrecord -v driveropts=burnfree -overburn -dao dev=/dev/hdd ~/burntemp.iso"
alias burniso="cdrecord -v driveropts=burnfree -overburn -dao dev=/dev/hdd"
alias mktemp="mkisofs -rJ -o /home/nuclearfusi0n/burntemp.iso -V"
#alias su="su -"
alias gimp="gimp-1.3"
alias bemerge="ACCEPT_KEYWORDS=""~x86"" emerge"
alias bt4="btdownloadcurses.py --max_upload_rate 4 --responsefile"

source /etc/profile







/etc/profile:
if [ `/usr/bin/whoami` = 'root' ]
then
umask 022
else
umask 077
fi

if [ `/usr/bin/whoami` = 'root' ]
then
# Do not set PS1 for dumb terminals
if [ "$TERM" != 'dumb' ] && [ -n "$BASH" ]
then
export PS1="\[\033[1;36m\]\w\n\[\033[1;31m\]\u@\h: \[\033[1;34m\]\[\033[37m\]\$(/bin/ls -1 | /usr/bin/wc -l | /bin/sed 's: ::g') files \[\033[1;33m\]\$(/bin/ls -lah | /bin/grep -m 1 total | /bin/sed 's/total //')b\[\033[0m\] \\$ \[\033[00m\]"
fi
export PATH="/bin:/sbin:/usr/bin:/usr/sbin:${ROOTPATH}"
else
# Do not set PS1 for dumb terminals
if [ "$TERM" != 'dumb' ] && [ -n "$BASH" ]
then
export PS1="\[\033[1;36m\]\w\n\[\033[1;32m\]\u@\h: \[\033[1;34m\]\[\033[37m\]\$(/bin/ls -1 | /usr/bin/wc -l | /bin/sed 's: ::g') files \[\033[1;33m\]\$(/bin/ls -lah | /bin/grep -m 1 total | /bin/sed 's/total //')b\[\033[0m\] \\$ \[\033[00m\]"
fi
export PATH="/bin:/usr/bin:${PATH}"
fi
unset ROOTPATH

if [ -z "$INPUTRC" -a ! -f "$HOME/.inputrc" ]
then
export INPUTRC="/etc/inputrc"
fi

# Extract the value of EDITOR
[ -z "$EDITOR" ] && EDITOR="`. /etc/rc.conf 2>/dev/null; echo $EDITOR`"
[ -z "$EDITOR" ] && EDITOR="`. /etc/conf.d/basic 2>/dev/null; echo $EDITOR`"
[ -z "$EDITOR" ] && EDITOR="/bin/nano"
export EDITOR
 
Originally posted by: BingBongWongFooey
To email a 5 day forecast to my cell phone every morning before I wake up, I have a cron job that runs this at 6am everyday (this one's nasty!)
Right you are, one perl script could do everything you're trying to do there... 😀

Having discovered perl, I don't use many bash scripts anymore, but I have a script (named compile_kernel.sh) that will compile a kernel, install the files to the appropriate places, re-execute lilo, and even re-install my NVidia drivers. 🙂 Yes, I know it's inefficient, I intend on rewriting it in perl at some point. 🙂

#!/bin/sh
LOGFILE="/var/log/kernelcomp.log"
KERN_SRC="/usr/src/linux"
NV_DRV="/usr/src/NVdriver/NV-4194.run"

APPEND_VER="$1" # kernel version numbering extension.
CLEAN_ALL="$2" # whether or not to run make mrproper, should be 'yes' or 'no'.

if [ "${APPEND_VER}" == "" ]; then
echo "Usage: compile_kernel.sh <version number> [yes|no]"
exit -1
fi

echo "Preparing to compile and install the kernel. If this fails, please check the logfile ${LOGFILE}"

cd ${KERN_SRC}
if [ "$?" != "0" ]; then
echo "Failed CDing to the kernel source directory ${KERN_SRC}"
exit -1
fi

if [ "${CLEAN_ALL}" == "" || "${CLEAN_ALL}" == "no" ]; then
make clean > ${LOGFILE}
if [ "$?" != "0" ]; then
echo "Failed 'make clean' in kernel sources!"
exit -1
fi
else
make mrproper > ${LOGFILE}
if [ "$?" != "0" ]; then
echo "Failed to 'make mrproper' in kernel sources!"
exit -1
fi
fi

# run make menuconfig
make menuconfig >> ${LOGFILE}
if [ "$?" != "0" ]; then
echo "make menuconfig exited improperly!"
exit -1
fi

# run make dep
make dep >> ${LOGFILE}
if [ "$?" != "0" ]; then
echo "make dep exited improperly!"
exit -1
fi

# run make modules
make modules >> ${LOGFILE}
if [ "$?" != "0" ]; then
echo "make modules exited improperly!"
exit -1
fi

# install modules
make modules_install >> ${LOGFILE}
if [ "$" != "0" ]; then
echo "Module installation failed!"
exit -1
fi

# copy system.map file to the boot dir.
cp ${KERN_SRC}/System.map /boot/System.map-${APPEND_VER}
if [ "$?" != "0" ]; then
echo "Failed copying System.map file to the /boot/ directory!"
exit -1
fi

# copy kernel image to the boot dir.
cp ${KERN_SRC}/arch/i386/boot/bzImage /boot/vmlinuz-${APPEND_VER}
if [ "$?" != "0" ]; then
echo "Failed copying kernel iamge to the /boot/ directory!"
exit -1
fi

echo "Compile and copy should be complete."

EDIT: Added my seti script. This thing inits seti@home (both clients) on my system. With some hacking, you could use it for your own purposes. It also includes a 'status' flag that allows you to see the progress of each client.

#!/bin/sh
SETI1=/home/user/seti
SETI2=/home/user/seti2


case "$1" in
start)
cd $SETI1
./setiathome > /dev/null &
cd $SETI2
./setiathome > /dev/null &
;;
stop)
kill `cat $SETI1/pid.sah`
kill `cat $SETI2/pid.sah`
;;
restart)
$0 stop
$0 start
;;
status)
CLSETI1PROG=`cat $SETI1/state.sah | grep prog | sed 's/=/ /' | awk '{printf "%0.2f%", $2 * 100}'`
CLSETI2PROG=`cat $SETI2/state.sah | grep prog | sed 's/=/ /' | awk '{printf "%0.2f%", $2 * 100}'`
SETI1TOTAL=`cat $SETI1/user_info.sah | grep nresults | sed 's/=/ /' | awk '{print $2}'`
SETI2TOTAL=`cat $SETI2/user_info.sah | grep nresults | sed 's/=/ /' | awk '{print $2}'`

if [ "$SETI1TOTAL" -gt "$SETI2TOTAL" ]
then
SETITOTAL=$SETI1TOTAL
else
SETITOTAL=$SETI2TOTAL
fi
UPSTR1=`ps aux | awk '{print $2}' | grep \`cat $SETI1/pid.sah\``
if [ ! "$UPSTR1" ]
then
UPSTR1="Not Running."
else
UPSTR1="Running."
fi
UPSTR2=`ps aux | awk '{print $2}' | grep \`cat $SETI2/pid.sah\``
if [ ! "$UPSTR2" ]
then
UPSTR2="Not Running."
else
UPSTR2="Running."
fi
echo -e "\n\t\t\t Seti At Home Clients "
echo -e "\t\t\t==============================="
echo -e "\t\t\t Processes"
echo -e "\t\t\t Client #1 is $UPSTR1"
echo -e "\t\t\t Client #2 is $UPSTR2"
echo -e "\t\t\t==============================="
echo -e "\t\t\t Progress"
echo -e "\t\t\t Client #1: $CLSETI1PROG"
echo -e "\t\t\t Client #2: $CLSETI2PROG"
echo -e "\t\t\t==============================="
echo -e "\t\t\t Data Units Processed: $SETITOTAL"
echo -e "\t\t\t===============================\n\n"
;;
*)
echo -e "\n\tUsage: seti {start|stop|restart}\n\n"
;;
esac
 
When I had a whole lot of time to kill, I put together this script to automagically update my install of tomenet every night. I could have probably made it better, but I stopped playing that particular game, so....
#Setup the variables needed in order to download the file
today=$(eval date +%y%m%d)
filename=tomenet-cvs-snapshot-$today
site="http://angband.oook.cz/tomenet-nightly"
tomenetdir="/usr/local/lib/tomenet"

#Move to the temporary dir
cd /tmp

#Fetch the file
if wget $site/$filename.tar.bz2
then
echo "File has been downloaded successfully"
else
echo "An error has occured while downloading now aborting script"
exit 1
fi

#Extract the file
bzip2 -d ./$filename.tar.bz2
tar xvvf ./$filename.tar

#Cleanup
rm -f ./$filename.tar
rm -f ./$filename.tar.bz2

#Build the file
cd ./pm/src

if make
then
echo "Tomenet has been compiled successfully"
else
echo "An error has occured while compiling, unable to update tomenet"
cd /
rm -rf /tmp/pm
exit 1
fi

#Backup the old tomenet
rm -f $tomenetdir.tar.bz2
tar cvvf $tomenetdir.tar $tomenetdir
bzip2 -zv $tomenetdir.tar

#Kill all tome stuff
killall tomenet.server
killall tomenet
killall evilmeta
killall tomenet.console

#Update tome
mkdir /tmp/tmdata
mv -f $tomenetdir/lib/data /tmp/tmdata
rm -rf $tomenetdir
cd ..
mv -f ./src $tomenetdir
mv -f ./lib $tomenetdir/lib
mv -f /tmp/tmdata $tomenetdir/lib/data
cd $tomenetdir
ln -s /etc/tomenet.cfg

#Create executable links
mkdir /usr/games
cd /usr/games
ln -s $tomenetdir/tomenet
ln -s $tomenetdir/tomenet.server
ln -s $tomenetdir/tomenet.console

#More cleanup
cd /
rm -rf /tmp/pm
rm -rf $tomenetdir/lib/data/data

#Restart tome server
cd $tomenetdir
./tomenet.server &

#Mission accomplished, so pack it up and head home
exit 0

And here's a perl script that I use to convert all of the filenames in a directory to lowercase. I can't remember whether or not I actually wrote it :/
#!/usr/bin/perl
use Symbol;
use Cwd;
my $filetype;
my $DH = Symbol::gensym();
my $dir = cwd();
my $filetype=$ARGV[0];

opendir ($DH , $dir);
while ($filename = readdir($DH)) {
if ($filename =~ $filetype) {
&lcName($filename);
}
}

exit;

sub lcName {
$newfilename = $filename;
$newfilename =~ tr/A-Z/a-z/;
if ((-r $filename) && (-w $filename)) { rename($filename, $newfilename);
print " Renamed: $filename to $newfilename\n";}
}

And here is a python..... errr..... perl script that I made to seperate all of my music files into directories for each author.
# Loads all neccesary libraries
use Symbol;
use Cwd;

# Declares the needed variables
my $DirHandle = Symbol::gensym();
my $CurrDir = cwd();
my %Headers;
my @SplicedFile;
my $NumOfFiles = 1;
my $CurrFile = 1;

#Opens a directory and reads its contents
opendir( $DirHandle, $CurrDir );
@DirContents = readdir( $DirHandle );
closedir( $DirHandle );

#Updates the hash keys
foreach $file ( @DirContents ) {
@SplicedFile = split( " - ", $file);

if( $Headers{@SplicedFile[0]} == null ){
$Headers{@SplicedFile[0]} = "1";
print "Key: @SplicedFile[0] (with value $Headers{@SplicedFile[0]}) was filled \n"
} else{
$Headers{@SplicedFile[0]}++;
print "Key: @SplicedFile[0] (with value $Headers{@SplicedFile[0]}) was updated \n"
}

$NumOfFiles++;
} print "\n\nSorting complete: $NumOfFiles total\n\n\n";

#Prints out the key summary
foreach $key ( keys( %Headers ) ) {
print "$key has $Headers{$key} entries\n"
}


#Creates the directories for the files
foreach $key ( keys( %Headers ) ) {
if( $Headers{$key} > 2 ) {
unless ( -d $key ) {
mkdir( $key, 0777 );
}
} else {
unless ( -d "miscellaneous" ) {
mkdir( "miscellaneous", 0777 );
}
}
} print "\n\nCreated directories\n\n\n";

#Adds the files to their directories
foreach $file ( @DirContents ) {
@SplicedFile = split( " - ", $file);

if( $Headers{@SplicedFile[0]} > 2 ) {
if( -f $file ){
@args = ( "cp", $file, "./$SplicedFile[0]" );
system(@args);
}
} else {
if( -f $file ){
@args = ( "cp", $file, "./miscellaneous" );
system(@args);
}
}

print "Copied file $CurrFile of $NumOfFiles... \n";
$CurrFile++;
} print "\n\n... OPERATION COMPLETED ...\n\n\n";
Is there any way to perserve whitespace!!!!
rolleye.gif
 
Originally posted by: BingBongWongFooey
You are on crack, that's perl, not python! :Q

Good point 😛 I did recode the same thing in python, which probably got me confused, but I can't seem to find it right now.......
 
Back
Top