PDA

View Full Version : Bash script to C++


ProgrammingNoob
07-14-2005, 04:25 AM
I wrote a script to handle a problem, but the security guys say they want something in c++. I'm completely new to c++(just getting to functions in the class I'm taking), and have no idea how to get this done. Any help would be very much appreciated since I don't even know where to start.

Here's what I've been using:
#!/bin/bash

FakeImagerPath[0]="/Volumes/D$/Imager1/"
FakeImagerPath[1]="/Volumes/D$/Imager2/"
RealImagerPath[0]="/Volumes/DirecTiff1/"
RealImagerPath[1]="/Volumes/DirecTiff2/"


SUBSTITUTION='tif'
PATTERN='inf'
SED=`which sed`
MV=`which mv`
SLEEP=`which sleep`


# Never stop until the Process is killed.
while [ 1 ]
do
# We've had up to 4 imagers at one time, so we account for all of them.
element_count=${#FakeImagerPath[@]}
index=0
# Do it for each Imager.
while [ "$index" -lt "$element_count" ]
do
# A simple test to see if our path exists
if cd ${FakeImagerPath[$index]} >/dev/null 2>&1
then
for FILE in *.inf
do
# When there are no inf files present *.inf is returned
if test "$FILE" != "*.inf"
then
# A simple test to see if our path exists
if cd ${RealImagerPath[$index]} >/dev/null 2>&1
then
# Get the name of the TIFF for the current inf
TIFFILE=`echo "$FILE" | $SED -e "s/$PATTERN/$SUBSTITUTION/"`
# Pause a moment to ensure the file is completely written
$SLEEP 1
# Move both files to the Imager(inf first)
$MV ${FakeImagerPath[$index]}"$FILE" ${RealImagerPath[$index]}
$MV ${FakeImagerPath[$index]}"$TIFFILE" ${RealImagerPath[$index]}
fi
fi
done
let "index = $index + 1"
fi
done
#Sleep for 10 seconds. No reason to constantly poll the folder.
$SLEEP 10
done