Convert Bash shell script to Korn shell script

Convert Bash shell script to Korn shell script

am 23.11.2004 01:42:34 von jrefactors

The following bash script works fine to delete all files that are
older than $1 minutes. To execute this script,
bash cleanup +10

find /mypath -type f -cmin $1 -exec rm -f {} \;

Unfortunately, now I just realize I need to make it work in Korn
Shell. Even I
change the header from #!/bin/bash to #!/usr/bin/ksh, and execute the
script by ksh cleanup +10, it still have
different errors:

cleanup[9]: -cmin: not found.
cleanup[10]: -type: not found.


Looks like it doesn't work anymore. I think I need to re-write the
Korn Shell script that do the task.
I tried to search for equivalent Korn shell commands but unsuccessful.


Please help. thanks!!

Re: Convert Bash shell script to Korn shell script

am 23.11.2004 03:12:50 von William Park

Matt wrote:
> The following bash script works fine to delete all files that are
> older than $1 minutes. To execute this script,
> bash cleanup +10
>
> find /mypath -type f -cmin $1 -exec rm -f {} \;
>
> Unfortunately, now I just realize I need to make it work in Korn
> Shell. Even I
> change the header from #!/bin/bash to #!/usr/bin/ksh, and execute the
> script by ksh cleanup +10, it still have
> different errors:
>
> cleanup[9]: -cmin: not found.
> cleanup[10]: -type: not found.
>
>
> Looks like it doesn't work anymore. I think I need to re-write the
> Korn Shell script that do the task.
> I tried to search for equivalent Korn shell commands but unsuccessful.
>
>
> Please help. thanks!!

Try typing it out on your command-line. I don't think this is Bash/Ksh
issue.

--
William Park
Linux solution for data management and processing.

Re: Convert Bash shell script to Korn shell script

am 23.11.2004 14:27:24 von sharma__r

jrefactors@hotmail.com (Matt) wrote in message news:

>
> The following bash script works fine to delete all files that are
> older than $1 minutes. To execute this script,
> bash cleanup +10
>
> find /mypath -type f -cmin $1 -exec rm -f {} \;
>
> Unfortunately, now I just realize I need to make it work in Korn
> Shell. Even I
> change the header from #!/bin/bash to #!/usr/bin/ksh, and execute the
> script by ksh cleanup +10, it still have
> different errors:
>
> cleanup[9]: -cmin: not found.
> cleanup[10]: -type: not found.
>
>
> Looks like it doesn't work anymore. I think I need to re-write the
> Korn Shell script that do the task.
>

change 'find' to '/bin/find'.

probably your ksh has 'find' aliased.

Re: Convert Bash shell script to Korn shell script

am 23.11.2004 18:46:09 von jrefactors

> change 'find' to '/bin/find'. probably your ksh has 'find' aliased.

I tried it, it still doesn't work. Let me make the descriptions more
clear.

Here's the bash script that worked in home's Linux before, and then I
put this script
to Unix, and no longer works with error "ksh: bash: not found." I
guess the
Unix environment setting doesn't support bash scripts?

#!/bin/bash
find /usr/local/opt/WebSphere/AppServer/installedApps/proj1App.ea r/proj1.war/proj1/download
-type f -cmin $1 -exec rm -f {} \;

$ bash cleanup +5
ksh: bash: not found


I then replaced the header with #!/usr/bin/ksh, and it has another
error "-cmin is not a valid option."
#!/usr/bin/ksh
find /usr/local/opt/WebSphere/AppServer/installedApps/proj1App.ea r/proj1.war/proj1/download
-type f -cmin $1 -exec rm -f {} \;

$ ksh cleanup +5
find: 0652-017 -cmin is not a valid option.


I don't want to change any setting in unix, but I have no idea what to
do now. I guess I
need to re-write the bash shell script to korn shell script?


Thanks again. Please advise.

Re: Convert Bash shell script to Korn shell script

am 23.11.2004 19:04:42 von Stephane CHAZELAS

2004-11-23, 09:46(-08), Matt:
[...]
> I then replaced the header with #!/usr/bin/ksh, and it has another
> error "-cmin is not a valid option."
> #!/usr/bin/ksh
> find /usr/local/opt/WebSphere/AppServer/installedApps/proj1App.ea r/proj1.war/proj1/download
> -type f -cmin $1 -exec rm -f {} \;
>
> $ ksh cleanup +5
> find: 0652-017 -cmin is not a valid option.
[...]

-cmin is a GNU (and BSD) specific option. There's no equivalent
option in standard find.

Note that -cmin is for the inode last change time, I doubt this
is what you want.

If you want to remove the files that have not been modified
withing the last $1 minutes, then you can use perl:

#! /usr/bin/perl
use File::Find;
$minutes = $ARGV[0];
find sub { unlink if (-M) * 24 * 60 > $minutes },
"/usr/local/opt/WebSphere/AppServer/installedApps/proj1App.e ar/proj1.war/proj1/download"

(untested)

--
Stephane

Re: Convert Bash shell script to Korn shell script

am 23.11.2004 19:14:32 von William

"Matt" wrote in message
news:ba8a039e.0411230946.1a2ae394@posting.google.com...
>
> I then replaced the header with #!/usr/bin/ksh, and it has another
> error "-cmin is not a valid option."
> #!/usr/bin/ksh
> find
/usr/local/opt/WebSphere/AppServer/installedApps/proj1App.ea r/proj1.war/proj
1/download
> -type f -cmin $1 -exec rm -f {} \;

It isn't a valid option for the find on my machine, the only option it
supports is -ctime, which would do what you want. -Wm

Re: Convert Bash shell script to Korn shell script

am 23.11.2004 19:30:15 von Ed Morton

Matt wrote:
>>change 'find' to '/bin/find'. probably your ksh has 'find' aliased.
>
>
> I tried it, it still doesn't work. Let me make the descriptions more
> clear.
>
> Here's the bash script that worked in home's Linux before, and then I
> put this script
> to Unix, and no longer works with error "ksh: bash: not found." I
> guess the
> Unix environment setting doesn't support bash scripts?

Not necessarily, it just apparently isn't in "/bin" on your system. It
MAY be in "/usr/bin" (or elsewhere) in which case your shebang should be
"#!/usr/bin/bash" instead of "#!/bin/bash". That wouldn't solve your
main problem though. Your main problem has nothing whatsoever to do with
whether you're using a bash or ksh shell, it's which version of "find"
you're using as discussed elsethread.



> I don't want to change any setting in unix, but I have no idea what to
> do now. I guess I
> need to re-write the bash shell script to korn shell script?

No, you need to download and install GNU "find".

Ed.

Re: Convert Bash shell script to Korn shell script

am 23.11.2004 20:39:16 von dfrench

Matt wrote:
> The following bash script works fine to delete all files that are
> older than $1 minutes. To execute this script,
> bash cleanup +10
>
> find /mypath -type f -cmin $1 -exec rm -f {} \;
>
> Unfortunately, now I just realize I need to make it work in Korn
> Shell. Even I
> change the header from #!/bin/bash to #!/usr/bin/ksh, and execute the
> script by ksh cleanup +10, it still have
> different errors:
>
> cleanup[9]: -cmin: not found.
> cleanup[10]: -type: not found.
>
>
> Looks like it doesn't work anymore. I think I need to re-write the
> Korn Shell script that do the task.
> I tried to search for equivalent Korn shell commands but
unsuccessful.
>

Do the following:
1. Start a bash shell: "bash"
2. run the command "which find"
3. exit the bash shell: "exit"
4. start a ksh: "ksh"
5. run the command "which find"
6. exit the ksh
7. use the find command identified in the bash shell as
the path to the find command in the ksh script. The
path will probably be "/usr/local/bin/find"

--
Dana French

Re: Convert Bash shell script to Korn shell script

am 24.11.2004 11:12:11 von Bill Marcum

On Tue, 23 Nov 2004 12:14:32 -0600, William
wrote:
> "Matt" wrote in message
> news:ba8a039e.0411230946.1a2ae394@posting.google.com...
>>
>> I then replaced the header with #!/usr/bin/ksh, and it has another
>> error "-cmin is not a valid option."
>> #!/usr/bin/ksh
>> find
> /usr/local/opt/WebSphere/AppServer/installedApps/proj1App.ea r/proj1.war/proj
> 1/download
>> -type f -cmin $1 -exec rm -f {} \;
>
> It isn't a valid option for the find on my machine, the only option it
> supports is -ctime, which would do what you want. -Wm
>
-[cma]time searches for files according to the age in days, whereas
-[cma]min uses minutes. When the "min" options aren't available, you
can use touch and "find -newer" or "find ! -newer"


--
"At a scheduled time, the robot would pull the flush lever and scream as
it got sucked down the drain." --Kibo

Re: Convert Bash shell script to Korn shell script

am 24.11.2004 16:45:54 von Dan Mercer

When I see problems like this I want to go back to first principles.
What are you really trying to do. I will assume for now that you
want to run a script, either from batch or cron, to clean up a
temp directory. Let's assume every ten minutes you run the following
script as root to clean up /usr/tmp of files beginning with sh:

#!/usr/bin/ksh
VARDIR==/var/${0##*/}
TOUCHSTONE=$VARDIR/touchstone
[[ -d $VARDIR ]] || mkdir $VARDIR ||
{
print -u2 "Fatal error - can't make $VARDIR"
exit 1
}

trap '>$TOUCHSTONE' exit

cd /usr/tmp

for file in sh*
do
[[ -f $file ]] || continue
[[ $file -ot $TOUCHSTONE ]] || continue
rm -f $TOUCHSTONE
done


This is portable to all ksh versions and does not require any
external command other than rm

Dan Mercer