Difficulty with a couple commands porting from korn shell to bash


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Difficulty with a couple commands porting from korn shell to bash
# 1  
Old 03-01-2012
Difficulty with a couple commands porting from korn shell to bash

I am relatively new to shell scripting. I have a script I wrote that works fine in korn shell.

I need to make it work in bash on a different server.

There are a couple valid korn shell commands I am having difficulty finding the bash equivalents for.

At one point the scripts prompts the user for their IP to export display. The read command used in the kornshell version to control a timeout is not valid in bash:
Code:
# Prompt for IP address 
  echo "Enter your IP address and press Return: "
  if read -t 90 ipadd; then    #90 second timeout if no user input.
     export DISPLAY=$ipadd:0.0
  else
    echo "Too much time has elapsed. Terminating script."
    exit 1
  fi

The error generated is read: -t: unknown option.

Users are asked later to specify the binary they want to run. bash is not interpreting the kornshell command. They are giving a list of binaries then script goes to the directory the binaries are in, and, if it is a valid name, executes it. If it is not found it just returns and invalid message.

None of the binaries are being found even though they are valid. The if [ -f ....] construct is not working in bash.
Code:
if [ -f /path/to/binary/$variable ]; then
                /path/to/binary/$variable
        
            finished=1
    
            else
        
            echo "Invalid selection. Please try again."
 fi

Any suggestions would be greatly appreciated. Thank you for your time.
# 2  
Old 03-01-2012
On the original computer, what Operating System and version?
On the new computer, what Operating System and version?

Item 1) Standard "ksh" (ksh88) does not have "read -t". What ksh do you have?
Item 2) Please post sample values of $variable and matching error messages.


Ps: For X-Windows DISPLAY Environment Variable you should be able to detect your own IP address indirectly via an appropriate who am i command (syntax varies).
e.g. who -R am i or whatever is valid on your system and processed to extract the IP address.
Obviously this would remove the need for "read -t".

Last edited by methyl; 03-01-2012 at 08:38 PM.. Reason: corrections and addenda
# 3  
Old 03-01-2012
Thanks

Thank you for the suggestion methyl. I eliminated the read -t statement entirely.

Here is the exact error I am seeing with the is statement. I am trying to say if the variable is one thing, execute the listed commands. For anything else, check the relevant directory and if the bin file is there run it, if not throw an error. There is an issue with my elif statement.
The shell it worked on was ksh-20100202-1.el5_6.5 on Red Hat Enterprise Linux Server release 5.6 (Tikanga).
It it not working on version 3.2.25(1)-release (x86_64-redhat-linux-gnu) on Red Hat Enterprise Linux Server release 5.7 (Tikanga)
Code:
# Specify console to be run
tries=0
limit=3
finished=0


while [ ${finished} -eq 0 ] && [ ${tries} -lt ${limit} ]; do

        echo "Specify the executable you would like to run and press Return: "
        read console;

                if [[ ${console} == "mstrdiag" ]]; then  #specify log file if doing diagnostics.
                        echo "Please enter the name of your destination logfile."
                        echo "The log file you specify will be in the same location as the DSSErrors log."
                                touch /logs/out/${logfile}
                                chown `whoami`:staff /logs/out/${logfile}
                                chmod 775 /logs/out/${logfile}
                                finished=1
                                /test/apps/mstr/bin/$console

                elif [ -f /test/apps/mstr/bin/$console ]; then
                        /test/apps/mstr/bin/$console

                        finished=1

                        else

                        echo "Invalid selection. Please try again."
                fi


        tries=`expr ${tries} + 1`
done
+ [ 0 -eq 0 ]
+ [ 0 -lt 3 ]
+ echo Specify the executable you would like to run and press Return:
Specify the executable you would like to run and press Return:
+ read console
mstrconnectwiz
+ [ -f /test/apps/mstr/bin/mstrconnectwiz ]
+ echo Invalid selection. Please try again.
Invalid selection. Please try again.
+ expr 0 + 1
+ tries=1
+ [ 0 -eq 0 ]
+ [ 1 -lt 3 ]
+ echo Specify the executable you would like to run and press Return:
Specify the executable you would like to run and press Return:
+ read console

# 4  
Old 03-01-2012
What does ls -l /test/apps/mstr/bin/mstrconnectwiz say?
# 5  
Old 03-01-2012
Thanks for replying. The executable is in a root owned directory. I do not get root access. Sudo rights were applied so the commands in the script execute as root. If I ls -l I will just get permission denied. I did confirm with a unix admin that the file exists.
# 6  
Old 03-01-2012
OK, then what does sudo ls -l /test/apps/mstr/bin/mstrconnectwiz say? Or if the sudo rights are for the script itself, insert ls -l /test/apps/mstr/bin/mstrconnectwiz into the script to test its presence and or its readability of the directory it is in.

Last edited by Scrutinizer; 03-01-2012 at 10:28 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

Run automated bash commands from sh login shell

I use plink.exe to automate remote commands that return data to Windows machines. This works well on newer servers running Red Hat since the commands were developed for bash and the designated user's login shell is bash. I need to also support older servers which are running Solaris 10 but the... (5 Replies)
Discussion started by: randman1
5 Replies

2. Shell Programming and Scripting

UNIX Korn Shell to Linux Bash

Migrating Unix batch jobs (Korn Shell) running in HP-UX server to Linux environment. Hi All Please help me to understand the easiest way to migrate Kernel Shell scripts to Linux Bash. Also let me know 1. Any automated scripts or tools available for this. 2. Challenges and issues... (5 Replies)
Discussion started by: cpremesh
5 Replies

3. Shell Programming and Scripting

Need to understand a couple of Shell Logic

Hi, I am trying what the following loop does : for i in XYZ do for j in M1 R1 R2 R3 do if then kList="" n=1 while do kList="$kList $n" let n++ done There are a couple of loop as mentioned above for R1.R2.R3. (1 Reply)
Discussion started by: johnprince1980
1 Replies

4. Shell Programming and Scripting

[bash] run a shell who runs commands

Hi all. On X11 I'm on a shell ...shell_1 (/bin/bash). From here I want to open another shell window shell_2 who executes commands like "ls -l" or programs like ". /program"... so the "result" of commands shows in shell_2 window and not in shell_1. Is that possible ? (4 Replies)
Discussion started by: jerold
4 Replies

5. Shell Programming and Scripting

Parameters passed to commands but not working in Bash shell

Hi, I am trying to do this thing useing my shell bash ( sorry for my english ) I have in a file 63 hostnames, i wanna ask to the DHCP admin, to reserv that reserves 63 IP addresses of this hosts, using their mac address. I have thinked this script: for ((i=1;i<63;i++)); do arp $(head... (10 Replies)
Discussion started by: Cypress
10 Replies

6. Shell Programming and Scripting

Can BASH execute commands on a remote server when the commands are embedded in shell

I want to log into a remote server transfer over a new config and then backup the existing config, replace with the new config. I am not sure if I can do this with BASH scripting. I have set up password less login by adding my public key to authorized_keys file, it works. I am a little... (1 Reply)
Discussion started by: bash_in_my_head
1 Replies

7. UNIX for Advanced & Expert Users

Problem in running bash shell commands on HP-UX machine

Hello All, After login to the server we are explicitly calling /usr/local/bin/bash to activate bash shell properly. But since commands are not executing properly so I think it is not initialized well. I am facing following problems: 1) If I want to have a look on a particular file using tail... (6 Replies)
Discussion started by: abhishek0071
6 Replies

8. UNIX for Dummies Questions & Answers

what are some different commands in c shell and korn shell??

I am doing this simple script using c shell and korn shell. The commands I use are fgrep , ls, and also some redirecting. Is there any difference in using both of these commands in c shell and korn shell? Thanks and sorry for the stupid question. (1 Reply)
Discussion started by: EquinoX
1 Replies

9. UNIX for Dummies Questions & Answers

korn shell to bash - statement not working

Everything else seems to be working, but this isn't. Is it the "cat..." that is wrong of the condition? Thanks. cat tc_result.txt | while read LINE do if then let "files_run += 1"; echo "inside the if loop" # save current filetype case $LINE... (5 Replies)
Discussion started by: brdholman
5 Replies

10. Shell Programming and Scripting

KORN Shell - Spawn new shell with commands

I want to be able to run a script on one server, that will spawn another shell which runs some commands on another server.. I have seen some code that may help - but I cant get it working as below: spawn /usr/bin/ksh send "telnet x <port_no>\r" expect "Enter command: " send "LOGIN:x:x;... (2 Replies)
Discussion started by: frustrated1
2 Replies
Login or Register to Ask a Question