f



Convert Bash shell script to Korn shell script

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!!
0
jrefactors (362)
11/23/2004 12:43:45 AM
comp.os.linux.misc 33599 articles. 1 followers. amosa69 (78) is leader. Post Follow

7 Replies
1325 Views

Similar Articles

[PageSpeed] 29

>> On 22 Nov 2004 16:43:45 -0800,
>> jrefactors@hotmail.com (Matt) said:

> 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.

This indicates these tokens appear on *different* lines of the
script.

You're not showing us the *real* code.  I strongly suspect
this has absolutely nothing to do with the underlying
interpreter shell.
0
11/23/2004 1:43:37 AM
> Tony Curtis <tony_curtis32@yahoo.com> wrote in message > This indicates these > tokens appear on *different* lines of the
> script.
> 
> You're not showing us the *real* code.  I strongly suspect
> this has absolutely nothing to do with the underlying
> interpreter shell.

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.ear/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.ear/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.
0
jrefactors (362)
11/23/2004 5:40:54 PM
Matt wrote:
>>Tony Curtis <tony_curtis32@yahoo.com> wrote in message > This indicates these > tokens appear on *different* lines of the
>>script.
>>
>>You're not showing us the *real* code.  I strongly suspect
>>this has absolutely nothing to do with the underlying
>>interpreter shell.
> 
> 
> 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.ear/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.ear/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.

It seems that the shell is not the problem.

Compare the manpages of find on both systems.

-- 

Tauno Voipio
tauno voipio (at) iki fi

0
11/23/2004 7:06:28 PM
>> On 23 Nov 2004 09:40:54 -0800,
>> jrefactors@hotmail.com (Matt) said:

>> You're not showing us the *real* code.  I strongly suspect
>> this has absolutely nothing to do with the underlying
>> interpreter shell.

Thought so...

> 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?

Why would you think that?  If bash has been installed on this
machine, then you can use it in a shell script.  Just make
sure you get the path to it right.

e.g.

    $ which bash
    /usr/bin/bash

> find /usr/local/opt/WebSphere/AppServer/installedApps/proj1App.ear/proj1.war/proj1/download
> -type f -cmin $1 -exec rm -f {} \;

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

Is that really one long line above or is there a newline
before "-type"?  That would explain some of the other error
messages in your previous post.

> 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?

It's telling you what the problem is:

    find: 0652-017 -cmin is not a valid option.

The "find" program on this machine does not understand the
"-cmin" option.  (It's an IBM AIX box, right?).

Nothing to do with the interpreting shell at all.
0
11/23/2004 7:13:47 PM
>     find: 0652-017 -cmin is not a valid option.
> 
> The "find" program on this machine does not understand the
> "-cmin" option.  (It's an IBM AIX box, right?).
> 
> Nothing to do with the interpreting shell at all.

I just want to use one single line, but the editor put my text in the
next line, i don't know if CRLF is there.

Yes, it is IBM AIX. so the standard Unix or Solaris machine doesn't
support -cmin, or just IBM AIX? Now I use -atime instead

Thanks again!!
0
jrefactors (362)
11/23/2004 11:00:41 PM
>> On 23 Nov 2004 15:00:41 -0800,
>> jrefactors@hotmail.com (Matt) said:

> I just want to use one single line, but the editor put my
> text in the next line, i don't know if CRLF is there.

$ cat -n filename

> Yes, it is IBM AIX. so the standard Unix or Solaris machine
> doesn't support -cmin, or just IBM AIX? Now I use -atime
> instead

I think it's a GNU find thing.  Of course, in some
environments, you may be able to get that installed on your
AIX machine too.
0
11/23/2004 11:13:18 PM
On 2004-11-23, Matt <jrefactors@hotmail.com> wrote:
>>     find: 0652-017 -cmin is not a valid option.
>> 
>> The "find" program on this machine does not understand the
>> "-cmin" option.  (It's an IBM AIX box, right?).
>> 
>> Nothing to do with the interpreting shell at all.
>
> I just want to use one single line, but the editor put my text in the
> next line, i don't know if CRLF is there.
>
> Yes, it is IBM AIX. so the standard Unix or Solaris machine doesn't
> support -cmin, or just IBM AIX? Now I use -atime instead

Don't most/all shells support backslash as a line
continuation character?  Why not just add a backslash and
sidestep the problem?

For example, the following commands are equivalent:

    cat file1 file2 file3

and

    cat     \
      file1 \
      file2 \
      file3

Good luck.

Robert Riches
spamtrap42@verizon.net
(Yes, that is one of my email addresses.)
0
spamtrap42 (1175)
11/24/2004 2:23:04 AM
Reply: