Sorry for the late reply.
hicksd8
-----------
I created the jobs when logged in as root with the 'crontab -e' command. I do get the message that the jobs have been updated and the schedule and script do execute as you would expect.
Running the command with an absolute path, I get the same outcome as I do with a relative path and I get the full output from the command as if it was called from the command line.
Don
-----
It seems to be using /bin/sh as the shell even thou I requested that it uses bash with the shebang. The log file shows that when I issue the command from the CLI it uses bash.
I included the passed variable before the fstrim command is issued and it seems to recognise the variable without a problem. It's only after the fstrim command that the variable is not recognised!
The OS I'm using is Debian derivative Kali.
Script used to generate logfile below.
#!/bin/bash
###############################################################################
## SCRIPT TO TRIM SSD DRIVE
###############################################################################
## INPUT: $1 MOUNT POINT OF PARTITION
###############################################################################
LOG=/TRIM.LOG
echo "####" >> $LOG
echo $(date) >> $LOG
echo "SHELL is $SHELL" >> $LOG
if [ -z "$1" ];
then echo "No Target" >> $LOG
else echo "Trimming $1 $(fstrim -v $1)" >> $LOG
fi
Logfile from above script. Last line shows output from command manually issued at the CLI.
####
Tue Jun 9 03:31:01 BST 2015
SHELL is /bin/sh
Trimming /
####
Tue Jun 9 03:32:01 BST 2015
SHELL is /bin/sh
Trimming /
####
Tue Jun 9 03:33:01 BST 2015
SHELL is /bin/sh
Trimming /
####
Tue Jun 9 03:34:01 BST 2015
SHELL is /bin/sh
Trimming /
####
Tue Jun 9 03:35:01 BST 2015
SHELL is /bin/sh
Trimming /
####
Tue Jun 9 03:36:01 BST 2015
SHELL is /bin/sh
Trimming /
####
Tue Jun 9 03:36:28 BST 2015
SHELL is /bin/bash
Trimming / /: 380747776 bytes were trimmed
Just to see what would happed, I added the eval command just before fstrim that had no effect. Also I tried coding the variable differently i.e. ${1} and ${$1} also no change.
Interestingly, I did find this site that seems to suggest either using the 'bash -c' command or setting the EV 'SHELL=/bin/bash' actually in the crontab file.
How to change cron shell (sh to bash)? - Unix & Linux Stack Exchange
I'll give this a go and report back, but I'd still like to permanently change the shell crontab uses to Bash.
Thanks for your help.
---------- Post updated 09-06-15 at 12:23 AM ---------- Previous update was 08-06-15 at 11:50 PM ----------
Followed the file /bin/sh and it lead to a Debian specific shell called dash!
Apparently it is supposed to be compatible with bash as documented here
Unix Shells: Bash, Fish, Ksh, Tcsh, Zsh - Hyperpolyglot
using the same notation for passed parameters.
Doesn't seem to want to work with the EV set in the crontab file. Was going to change the /etc/crontab setting to SHELL=bin/bash but the whole system has been setup to run faster with dash as bash is much slower and who knows what changing shells will actually do.
If it is not the shell as it does seem to accept the variables that have been passed, could it be a problem with the fstrim command?