Cron Jobs: easy to make or farm it out?

I use a couple of cronjobs that reside on my website's "back end" at the hosting company that work like this:

At a set time each week, a batch of files, say from "Folder A." is moved to a folder, replacing the files there which have the same name (overwrites them).

If there are no files in folder A, an email is sent to me notifying me of  the lack of files AND then moves a group of same-named files from a standby folder.

I had these jobs created years ago by a freelancer. Now I need some more. I have a background (from more than ten years ago)  in BASIC and I'm wondering if I can learn how to do this fairly quickly and easily or if it would be better to farm it out to a freelancer. I;m not in a huge hurry, but the sooner, the better.

OR is there an online "auto-writer" type of service that takes your input and generates the code, either at no cost or for a proce?

Your thoughts?
RadioGeorgeOwner/ProgrammerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bill PrewIT / Software Engineering ConsultantCommented:
I would take a look at what the freelancer created and see how understandable they are to you.  they are likely written in one of the unix shells (bourne, c shell, etc) and it will be very different than Basic.  But if they aren't too complex you may be able to puzzle it out enough to feel some confidence doing it yourself.  Also, if the new needs are similar to the old ones, you may be able to copy and adjust some of those existing ones.

If you aren't comfortable then look for an affordable freelancer to do it, doesn't sound like it should be that large a job...

I'm not aware of any tools to automatically write unix shell scripts from descriptive info.  They may exist, I just am not aware...


»bp
David FavorLinux/LXD/WordPress/Hosting SavantCommented:
Likely easier to do this yourself.

If you farm out the work, you first have to design all the code, then explain it to someone, then give them access to your machine (shudder).

Since most CRON jobs, as Bill suggested, are simple BASH or PERL scripts, likely you can have a knew one written in a few minutes... without giving machine access to some random person.
Julian HansenCommented:
CRON is just a job scheduler - at specific times it calls a script based on a path.

What the script does is  the real bit that needs work - so you want to make sure that this part is done correctly. Once you have the script setting up the CRON bit is easy.

If you use CPanel or similar setting up a cron job is very straight forward.

If your background is BASIC then you would need to skill up in one of the more common scripting tools that could be used for a CRON job. Which one you use is dependent on your requirements - simple moving of files - you can use pretty much anything. If you need to access databases or do image or media manipulation it might require picking the right tool for the job.

When implementing a CRON job you first test the script out with manual execution on test  data. Get it working the way you want.
Once this is done you fix your paths - because a the cron process executes your script from a folder other than the one it resides in you need to make sure that any resources you are accessing can be found.

Once all that is working you setup your CRON entry and point it to your script.

Ancillary considerations such as logging, email notification and the like can further complicate development which might suggest you use an experienced resource rather than attempt a DIY - on the other hand - we learn by doing and more so from making mistakes so, depending on the mission critical nature of the data / site / files you are working with this might be a great opportunity to learn.
Dr. KlahnPrincipal Software EngineerCommented:
cron is not terribly difficult, just exacting.  The exacting part is not the cron script itself; it's getting the shell commands right, and then figuring out how many escapes must go around the arguments for the script to work.  It takes about a week to come up to speed, and regrettably about a week to lose that knowledge.  It's one of those things that is easy if you do it every day, otherwise ...

Attached is a commented cron script that does part of what you want to do.

root:~> cat update-geoip.sh
#!/bin/bash -e


GEOLITE_URL="https://geolite.maxmind.com/download/geoip/database/GeoLite2-Country-CSV.zip"
GEOLITE_ZIP="GeoLite2-Country-CSV.zip"
COUNTRY_URL="http://download.geonames.org/export/dump/countryInfo.txt"


#
# Switch to the GeoIP directory if not already there
#
echo "--> cd /usr/share/xt_geoip"
cd /usr/share/xt_geoip

#
# Remove anything remaining from previous failed runs
#
# Note:  DO NOT delete the existing BE and LE subfolders at this
#        time.  If the download fails the result would be no
#        database at all.
#
echo "--> rm -r GeoLite2*"
rm -r -f GeoLite2*
echo "--> rm countryInfo.txt"
rm -f countryInfo.txt
echo "--> rm GeoIP-legacy.csv"
rm -f GeoIP-legacy.csv

#
# Get the GeoIP ZIP file
#
echo "--> wget --no-check-certificate $GEOLITE_URL"
wget --no-check-certificate $GEOLITE_URL

#
# See if the ZIP file now exists
#
if [ ! -e $GEOLITE_ZIP ]; then
  echo "--> GeoIP ZIP file did not download"
  echo "--> Send email to root and stop here"
  /usr/sbin/sendmail root << EOM
From: Update_GeoIP
To: root
Subject: GeoIP update failed

GeoIP update failed.
Unable to download GeoIP ZIP file
$GEOLITE_ZIP
EOM
  exit
fi

#
# Unzip the ZIP file
#
echo "--> unzip $GEOLITE_ZIP"
unzip $GEOLITE_ZIP

#
# Delete the ZIP file
#
#echo "--> rm $GEOLITE_ZIP"
rm $GEOLITE_ZIP

#
# Move the received data directory to a standard name
#
echo "--> mv GeoLite2-Country-CSV_* GeoLite2"
mv GeoLite2-Country-CSV_* GeoLite2

#
# See if the critical GeoIP data files now exist
#
if [ ! -e "GeoLite2/GeoLite2-Country-Blocks-IPv4.csv" ] ||
   [ ! -e "GeoLite2/GeoLite2-Country-Blocks-IPv6.csv" ]; then
  echo "--> GeoIP data files are missing"
  echo "--> Send email to root and stop here"
  /usr/sbin/sendmail root << EOM
From: Update_GeoIP
To: root
Subject: GeoIP update failed

GeoIP update failed.
GeoIP data file(s) are missing
GeoLite2/GeoLite2-Country-Blocks-IPv4.csv
GeoLite2/GeoLite2-Country-Blocks-IPv6.csv
EOM
  exit
fi

#
# Get the country info data file
#
echo "--> wget --no-check-certificate $COUNTRY_URL"
wget --no-check-certificate $COUNTRY_URL

#
# See if the country info data file now exists
#
if [ ! -e "countryInfo.txt" ]; then
  echo "--> Country info data file did not download"
  echo "--> Send email to root and stop here"
  /usr/sbin/sendmail root << EOM
From: Update_GeoIP
To: root
Subject: GeoIP update failed

GeoIP update failed.
Unable to download country info data file
$COUNTRY_URL
EOM
  exit
fi

#
# Build an old format data file from the new format data files
#
echo "--> cat ./GeoLite2/GeoLite2-Country-Blocks-IPv{4,6}.csv | ./convert_GeoLite2.pl ./countryInfo.txt > /usr/share/xt_geoip/GeoIP-legacy.csv"
cat ./GeoLite2/GeoLite2-Country-Blocks-IPv{4,6}.csv | ./convert_GeoLite2.pl ./countryInfo.txt > /usr/share/xt_geoip/GeoIP-legacy.csv

#
# Delete the downloaded data files
#
echo "--> rm -r GeoLite2"
rm -r GeoLite2
echo "--> rm countryInfo.txt"
rm country_Info.txt

#
# Preserve the old BE and LE directories just in case
#
echo "--> rm -r -f LastBE LastLE"
rm -r -f LastBE LastLE
echo "--> mv BE LastBE"
mv BE LastBE
echo "--> mv LE LastLE"
mv LE LastLE

#
# Convert the generated database to the xtables GeoIP format
#
echo "--> /usr/lib/xtables-addons/xt_geoip_build -D /usr/share/xt_geoip ./GeoIP-legacy.csv"
/usr/lib/xtables-addons/xt_geoip_build -D /usr/share/xt_geoip ./GeoIP-legacy.csv

#
# Delete the remaining data files
#
echo "--> rm countryInfo.txt"
rm countryInfo.txt
echo "--> rm GeoIP-legacy.csv"
rm GeoIP-legacy.csv

#
# Notify root that the update succeeded
#
echo "--> Send notification email to root"
/usr/sbin/sendmail root << EOM
From: Update_GeoIP
To: root
Subject: Weekly update of xtables GeoIP completed

Weekly update of xtables GeoIP database successful.
EOM
echo "xtables GeoIP database update completed"

root:~>

Open in new window


One thing I would note:  Anything that might ever change -- directories, drive names, file names -- make it a variable and define it at the top.  This is partially done in the example above.  Then if any of these things change, there is one location to look in, one thing to change, and not the entire script.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
RadioGeorgeOwner/ProgrammerAuthor Commented:
The fabulous example provided by Dr. Klahn and the very descriptive comments by Julian combine to make my decision a lot easier. Thanks to them for taking as much time as they did to make a comprehensive picture.

So what's my course of action?

I'm going to use a freelancer. This id what I've done once before, but it appears the one I used is either unavailable or not interested now. I simply have too much going on right now and do not want to become bogged down with a project that likely will have its fair share of testing and tweaking to finalize.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.