Create a Post
cancel
Showing results for 
Search instead for 
Did you mean: 
Ants
Contributor

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

 

0 Kudos
2 Replies
Nicholas_Cuba
Contributor
Contributor

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)

 

 

 

Ants
Contributor

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

0 Kudos

Leaderboard

Epsum factorial non deposit quid pro quo hic escorol.

Upcoming Events

    CheckMates Events