Help (again)

 
SOLVED
Go to solution
Adam W.
Valued Contributor

Help (again)

Guru's, hello again. I am having a bit of an issue with the attached script. (You all out there helped with) I am getting several errors like the one below , when the script runs:

/tmp/list1.29752 not found


*************************************************
Cron: The previous message is the standard output
and standard error of one of your crontab commands:

/usr/local/bin/filesystemcheck.sh


IS there a way I can modify the script to use "touch" to create necesary files to ensure they are there?
There are two types of people in the world, Marines and those who wish they were.
9 REPLIES 9
James R. Ferguson
Acclaimed Contributor

Re: Help (again)

Hi Adam:

Most certainly you can use 'touch' to create files to insure their presence. Of course, you can also test for their presence too:

# FILE=/tmp/mylist
# [ -f "${FILE}" ] && echo "${FILE} exists" || touch ${FILE}

Regards!

...JRF...
Adam W.
Valued Contributor

Re: Help (again)

James, would I slide those in after the dt= line?
There are two types of people in the world, Marines and those who wish they were.
James R. Ferguson
Acclaimed Contributor
Solution

Re: Help (again)

Hi (again) Adam:

> would I slide those in after the dt= line?

I don't see anything in the attached script that has the string "list" in it.

As for this code:

dt=`date +bdf%m%d%y%H`
existence=`ll /tmp | grep $dt`
if [ -n "$existence" ]
then
exit
fi

...It assumes that the file named by the value of '${dt}' exists if it lives in the '/tmp' directory. A much better approach might be:

cd /tmp && exit 1
dt=$(date +bdf%m%d%y%H)
[ -f "${dt}" ] || exit

...which would exit if the file didn't exist.

If you want to create the file if it isn't there, do what I first suggested:

cd /tmp && exit 1
dt=$(date +bdf%m%d%y%H)
[ -f "${dt}" ] || touch ${dt}

Regards!

...JRF...



Adam W.
Valued Contributor

Re: Help (again)

James I tried it with:

cd /tmp && exit 1
dt=$(date +bdf%m%d%y%H)
[ -f "${dt}" ] || touch ${dt}


and I added a -x to the shebang, but all it does is gives me:
+cd
+exit

and nothing else runs.
There are two types of people in the world, Marines and those who wish they were.
James R. Ferguson
Acclaimed Contributor

Re: Help (again)

Hi (again) Adam:

> cd /tmp && exit 1

Oops, my reversed thinking. This says "cd to /tmp" but if you DO (successfully) then 'exit' ! I meant:

# cd /tmp || exit 1

...meaning if you can't change directories to /tmp, then exit.

Regards!

...JRF...
Adam W.
Valued Contributor

Re: Help (again)

Ah ok. LOL. Happens to us all. One last question though. When I run it with the -x after the shabang I get this in the output:

+ [ -fbdf03030910]
/usr/local/bin/filechecktest.sh[23]: test: A ] character is missing.


Thoughts on it?
There are two types of people in the world, Marines and those who wish they were.
James R. Ferguson
Acclaimed Contributor

Re: Help (again)

Hi Adam:

> usr/local/bin/filechecktest.sh[23]: test: A ] character is missing

...means that at (about) line-23 of your script in a 'test' operation, a bracket wasn't found where/when expected.


Since you see:

+ [ -fbdf03030910]

I you didn't observe the proper whitespace rules (the shell is picky). Be sure you wrote:

[ -f "${dt}" ] || touch ${dt}

...note too that we double-quote the variables in the 'test' command (that in square brackets). This protects us from errors if the 'dt' variable is empty, which would evaluate syntatically OK.

Compare these:

# XFILE=""
# [ -f ${XFILE} ] || echo no-file
sh: test: Specify a parameter with this command.

...with:

[ -f "${XFILE}" ] || echo no-file
no-file

Regards!

...JRF...

...wh

Adam W.
Valued Contributor

Re: Help (again)

Got it! Was missing a space. James, Always a pleasure Sir. Thank you (once again) for your help.
There are two types of people in the world, Marines and those who wish they were.
Dennis Handly
Acclaimed Contributor

Re: Help (again)

>Was missing a space

I would also suggest a space after -f or any other test operator.