bash select command - linux

I'm trying to run a script that uses the select command and I get error below. I'm running the most recent version of ubuntu. Why does it say the commands are not found?
#!/bin/bash
# Scriptname: runit
PS3= "Select a program to execute: "
select program in 'ls -F' pwd date cal exit
do
$program
done
This is the output:
runit.sh: 3: Select a program to execute: : not found
runit.sh: 4: select: not found
runit.sh: 5: Syntax error: "do" unexpected

Delete the space after the equal sign:
PS3= "Select a program to execute: "
^

Related

How to call Oracle SQL query using bash shell script

How to call a sql query using bash shell script. I tried the below but seems there is some syntax error:
#!/bin/sh
LogDir='/albt/dev/test1/test2/logs' # log file
USER='test' #Enter Oracle DB User name
PASSWORD='test' #Enter Oracle DB Password
SID='test' #Enter SID
sqlplus -s << EOF > ${LogDir}/sql.log
${DB_USER_NAME}/${DB_PASSWORD}#${DB_SID}
SELECT count(1) FROM dual; # SQL script here to get executed
EOF
var=$(SELECT count(1) FROM dual)
I'm getting - unexpected token error
#!/bin/sh
user="test"
pass="test"
var="$1"
sqlplus -S $user/$pass <<EOF
SELECT * FROM tableName WHERE username=$var;
exit;
EOF
I'm getting - sqlplus: command not found -- when I run the above script
Can anyone guide me?
In your first script, one error is in the use of count(1). The whole line is
var=$(SELECT count(1) FROM dual)
This means that the shell is supposed to execute a program named SELECT with the parameters count(1), FROM and dual, and stores its stdout into the variable var. I think you want instead to feed a SELECT command into sqlplus, i.e. something like
var=$(sqlplus .... )
In your second script, the error message simply means that sqlplus can not be found in your path. Either add it to the PATH or provide the absolute path to the command explicitly.

execute multiple commands assigned to a single variable - bash

I would like to ask the user to enter a command that will be executed, but I don't understand why I can't assign two commands to the same variable.
Here is the code:
user#localhost:~# read -ep "command: " cmd ; "$cmd"
and the result:
command: id ; date
-bash: id ; date : command not found
but if I type a single command, it works.
Thanks for your help

How to compare user input with array and execute command?

I am trying to write a script to login into different systems by providing system name as input and making it variable by read option. However when i try to compare it with defined Array it's throwing me error and stating command not found.
Succeeded in making use input as variable but not able to compare it properly with defined array.
Below is the code i have written.
#!/bin/bash
cluster=("namico1c.mylabserver.com","namico2c.mylabserver.com")
echo "Please enter a Cluster Name to login: "
read clname
for item in ${cluster[#]};do
echo ${item};
if ["${clname}"="${item}"]; then
ssh test#$clname
else
echo "Cluster is not correct"
fi
done
[test#namico3c ~]$ ./test.sh
Please enter a Cluster Name to login:
namico1c.mylabserver.com
namico1c.mylabserver.com,namico2c.mylabserver.com
./test.sh: line 7: [namico1c.mylabserver.com=namico1c.mylabserver.com,namico2c.mylabserver.com]: command not found
Cluster is not correct
alternative:
#!/bin/bash
cluster=("namico1c.mylabserver.com" "namico2c.mylabserver.com")
select clname in "${cluster[#]}"; do
ssh test#$clname
break
done

Getting bash script to enter in numbers in an 'interactive mode' prompt

There is an interactive mode that can be turned on in the program ORCA I am using by typing in the following command:
module load openmpi/2.1.2 orca/orca_4_0_1_2_linux_x86-64_openmpi202
Once this is enabled, I can give it a command to plot a graph with:
orca_plot IPC_CAS1_restart2f-NEVPT2.gbw -i
The program then offers me choices, which I can choose from by entering a number into the prompt. I wish to automate this process by having a bash script that enters a specific sequence of numbers for me (i.e. 1, then 3, then 2, then 7 for example).
My script looks like the following,
#!/bin/bash
module load openmpi/2.1.2 orca/orca_4_0_1_2_linux_x86-64_openmpi202
orca_plot IPC_CAS1_restart2f-NEVPT2.gbw -i
1
3
2
7
I get the messages
"line 4: 1: command not found", "line 5: 3: "command not found", "line 7: 2: command not found", "line 8: 7: command not found".
How can I fix this?
You need to convert those lines in the script into input to orca_plot. Use a heredoc:
#!/bin/bash
module load openmpi/2.1.2 orca/orca_4_0_1_2_linux_x86-64_openmpi202
orca_plot IPC_CAS1_restart2f-NEVPT2.gbw -i << EOF
1
3
2
7
EOF

Hbase scan commands into a text file in windows

Is it possible to capture the
hbase command "scan table" to a textfile.
The command goes like this :
hbase(main):001:0>scan sampletable
I tried using the command prompt command
hbase(main):001:0>scan sampletable > textfile.txt
but gives error as "wrong number of arguments"
I tried with the following commands as well :
hbase(main):001:0>echo "scan 'sampletable'" | hbase shell | grep "^ " > registration.txt
but there is exception "unrecognised characters ^ " in the command
You cannot execute linux commands like echo, hbase etc in hbase shell. You need to execute these commands in windows power shell.
Exit from hbase shell and execute the below command
echo "scan 'sampletable'" | hbase shell | grep "^ " > registration.txt

Resources