- CheckMates
- :
- Products
- :
- Quantum
- :
- Management
- :
- Custom Gaia Script not working
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
Are you a member of CheckMates?
×- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Custom Gaia Script not working
Hi All,
So.. I am trying to do a simple script copy task and need a second pair of eyes please as i cannot get it working..
My goal is to set a cron task to run a script once a day and copy the newest file (pdf reports automatically created daily) from folderA (MY_DIR) to folderB (DEST) on the R80.10 CMA (logged in as admin)
---------------------------------------------
#!/bin/bash
MY_DIR="/var/tmp/"
DEST="/home/admin/"
FILEEXT="pdf"
NEWEST=`ls -tr1d "${MY_DIR}"*.${FILEEXT} | tail -1`
if [ -z "${NEWEST}" ] ; then
echo "No file to copy"
exit 1
else
echo "Copying ${NEWEST}"
cp -p "${NEWEST}" "${DEST}"
fi
---------------------------------------------
but when running the script i get the following error..
[Expert@CMA:0]# ./sascopy.sh
Copying ls -tr1d "${MY_DIR}"=*.${FILEEXT} | tail -1
cp: cannot stat `ls -tr1d "${MY_DIR}"=*.${FILEEXT} | tail -1': No such file or directory
[Expert@CMA:0]#
If I run 'ls -tr1d /var/tmp/ | tail -1' manually I can see the file and output is the full dir listing.
I suspect this line here to be the problem..
NEWEST=`ls -tr1d "${MY_DIR}"*.${FILEEXT} | tail -1`
thanks in advance
ants
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I think this line in your output is the issue's tell
- Copying ls -tr1d "${MY_DIR}"=*.${FILEEXT} | tail -1
The commands inside the grave accents aren't being processed, they are taken as a literal string for the value of ${NEWEST}. Shouldn't it read something like
- Copying /var/tmp/foo.pdf
Check the characters typed and make sure they are grave accents or try replacing the grave accents with $( )
- NEWEST=$(ls -tr1d "${MY_DIR}"*.${FILEEXT} | tail -1)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for the response..
I managed to get it working with the following in the end..
NEWEST=$(ls -tr1d ${MY_DIR}*.pdf 2>/dev/null | tail -1)
cheers
