Operating System - HP-UX
1848046 Members
2930 Online
104022 Solutions
New Discussion

problem with writing a wrapper

 
SOLVED
Go to solution
Onur Sirin_1
Frequent Advisor

problem with writing a wrapper

Hi all,
I'm writing a wrapper for crontab command like below:

--------------------------------------------
#!/usr/bin/sh
#
# Replace crontab with a wrapper
# Written by M.B.
#

if [ `expr index "$1" "[\*,\?]"` -ne 0 ]

then
echo "Usage: crontab -l | -v | -r | -e [username]"
exit 1
else
exec /usr/bin/crontab.orig "$@"
fi
-----------------------------------------

But I have a problem,
when passing parameters to the script for example like "*a", if there is a file name ending with a (e.g baa), $1 value is "baa" not "*a", or another example,
let say that parameter is ?l, and if there is a file named ll, then $1 value is "ll" not "?l"!

I want to see the real values of the parameters in order to check if there is an incorrect value in the parameter.

How can I solve this problem?

Urgent!!!

Best regards

11 REPLIES 11
Rodney Hills
Honored Contributor

Re: problem with writing a wrapper

Standard shell interpolation is overridden by "quoting" the arguments, ie

crontab '*a'

This will prevent the shell from expanding the wildcard. You may also use the backslash, ie

crontab \*a

HTH

-- Rod Hills
There be dragons...
H.Merijn Brand (procura
Honored Contributor

Re: problem with writing a wrapper

exec /usr/bin/crontab.orig "$@"

groups all your args together to one single arg. Drop the (double) quotes.

I also dislike the use of 'else' after exit/exec, because it will never be executed as such

if [ $# -lt 1 -o `expr index "$1" "[\*,\?]"` -ne 0 ]; then
echo "Usage: crontab -l | -v | -r | -e [username]"
exit 1
fi

exec /usr/bin/crontab.orig $@



Enjoy, have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn
Onur Sirin_1
Frequent Advisor

Re: problem with writing a wrapper

Hi again,
Thanks very much for your answers.
Procura, I corrected the mistakes, thanks.
Rodney,
I have still the problem.
You wrote that I can use
"crontab \*" etc.
Yes I know it, but my users don't know. They can write crontab *l by mistake and they lose their original crontab file.
Therefore I want to prevent them doing mistakes by a wrapper.
But how can I pass a parameter including * or ?to the $1 like it's original value?

Thanks very much!

Rodney Hills
Honored Contributor

Re: problem with writing a wrapper

If your users don't understand how to run commands under a shell and how the rules with wildcard expansion work, then I would suggest you create a wrapper program that provides them a menu of tasks.

This way the user input can be controlled.

-- Rod Hills
There be dragons...
Onur Sirin_1
Frequent Advisor

Re: problem with writing a wrapper


:))),
Rodney, I agree with you but this still doesn't change the fact that I must do this.

Best regards

Dietmar Konermann
Honored Contributor
Solution

Re: problem with writing a wrapper

Your problem is not solvable by the wrapper. It's the calling shell that expands your wildcards. You may disable the filename generation by adding "set -f" to the user's .profile or /etc/profile.

Look, how the echo command is called:

$ echo .pro*
.profile

$ set -f
$ echo .pro*
.pro*

Best regards...
Dietmar.
"Logic is the beginning of wisdom; not the end." -- Spock (Star Trek VI: The Undiscovered Country)
Rodney Hills
Honored Contributor

Re: problem with writing a wrapper

Dietmer,

I agree, your solution is probabily the best.

Now as long as the user don't use some of the other "special" shell characters (like #, $, etc) they should be ok.... :-)

-- Rod Hills
There be dragons...
Onur Sirin_1
Frequent Advisor

Re: problem with writing a wrapper

Thanks Dietmer,
I'll try it.

Thanks all the others for their effort.

Best regards.
Dietmar Konermann
Honored Contributor

Re: problem with writing a wrapper

But prepared for complaints like: "Hey, Melike! My 'ls *.txt' does not work anymore!" :-)
"Logic is the beginning of wisdom; not the end." -- Spock (Star Trek VI: The Undiscovered Country)
Onur Sirin_1
Frequent Advisor

Re: problem with writing a wrapper

Hi again,
I can disable the wildcards file naming with using "set -f" command,
but how can I enable it again?

Thankss
Dietmar Konermann
Honored Contributor

Re: problem with writing a wrapper

set +f
"Logic is the beginning of wisdom; not the end." -- Spock (Star Trek VI: The Undiscovered Country)