Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Crontab not processing parameters sent to script. Post 302946380 by ASGR on Tuesday 9th of June 2015 12:23:27 AM
Old 06-09-2015
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.
Code:
#!/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.
Code:
####
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?

Last edited by ASGR; 06-09-2015 at 01:28 AM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

help me in sending parameters from sqlplus script to unix shell script

Can anybody help me out in sending parameters from sql*plus script to unix shell script without using flat files.. Initially in a shell script i will call sql*plus and after getting some value from some tables, i want that variable value in unix shell script. How can i do this? Please tell me... (2 Replies)
Discussion started by: Hara
2 Replies

2. Shell Programming and Scripting

call a script from another script passing parameters

I want to call script2 from script1 passing parameters. I want to read the parameters list in script1, check the local directory (for example - lpath1|lpath2|lpath3|lpath4|lpath5|) for the existance of files and set the` lcount` to the number of files in this folder (`... (2 Replies)
Discussion started by: Lenora2009
2 Replies

3. AIX

tuning network parameters : parameters not persist after reboot

Hello, On Aix 5.2, we changed the parameters tcp_keepinit, tcp_keepintvl and tcp_keepidle with the no command. tunrestore -R is present in inittab in the directory /etc/tunables we can clearly see the inclusion of parameters during reboot, including the file lastboot.log ... (0 Replies)
Discussion started by: dantares
0 Replies

4. Shell Programming and Scripting

want to pass parameters to awk script from shell script

Hello, I have this awk script that I want to execute by passing parameters through a shell script. I'm a little confused. This awk script removes duplicates from an input file. Ok, so I have a .sh file called rem_dups.sh #!/usr/bin/sh... (4 Replies)
Discussion started by: script_op2a
4 Replies

5. Programming

awk processing / Shell Script Processing to remove columns text file

Hello, I extracted a list of files in a directory with the command ls . However this is not my computer, so the ls functionality has been revamped so that it gives the filesizes in front like this : This is the output of ls command : I stored the output in a file filelist 1.1M... (5 Replies)
Discussion started by: ajayram
5 Replies

6. Shell Programming and Scripting

ksh processing options and parameters

I have a requirement where I need to process both options and parameters. command line call ie xxx.ksh -sid TEST1 -search_str LOCKED user1 user2 ..... I am using the following peice of code but I am usure how I can loop through all my parameters user1, user2, ... Note at the minium... (2 Replies)
Discussion started by: BeefStu
2 Replies

7. UNIX for Dummies Questions & Answers

Perl Script:how to find how many parameters are required to run the script

How to find how many parameters are required to run a Perl script? (1 Reply)
Discussion started by: Lakshman_Gupta
1 Replies

8. Shell Programming and Scripting

Passing Parameters to Crontab

Hello Experts, I have a requirement to pass some parameters to Linux cron tab. For ex: My default cron entry looks like this as below: ------------------------------- 55 10 * * --... (7 Replies)
Discussion started by: MaheshChaudhari
7 Replies

9. Shell Programming and Scripting

Shell script to create runtime variables based on the number of parameters passed in the script

Hi All, I have a script which intends to create as many variables at runtime, as the number of parameters passed to it. The script needs to save these parameter values in the variables created and print them abc.sh ---------- export Numbr_Parms=$# export a=1 while do export... (3 Replies)
Discussion started by: dev.devil.1983
3 Replies

10. UNIX for Beginners Questions & Answers

Parameters in crontab

I need to write a shell script which send an alert if a particular script scheduled in cron is not triggered. My concern is that particular script which is scheduled in crontab, runs at night but it requires a file from upstream system as a feed prior to execution. it waits for that file upto 4... (2 Replies)
Discussion started by: Ankit Srivastav
2 Replies
All times are GMT -4. The time now is 11:14 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy