#!/bin/bash
cat /etc/hosts
mkdir -p /var/tmp
mount 113.123.35.37:/vol/vol615/syb /var/tmp
In above script I am trying to add below predefined script/command (/var/tmp/db_tools)
This command in turn ask for user input, which will be always option 13 in my case.
Then User has to give '0' and at last exit
So three inputs need to give everytime whenever script/command (/var/tmp/db_tools) is running.
13
0
exit
su - sybase
/var/tmp/db_tools
root@host:/# su - sybase
sybase@host> /var/tmp/db_tools
*************************************************************************
Sybase DB tools
*************************************************************************
*************************************************************************
Select the action you want to perform:
1. Tempdb Setup Validation
2. Veritas QIO Validation
3. Sybase Error Logs Validation
4. File Validation
5. Sybase Database Space Usage Validation
6. Sybase Database & Device Usage Listing
7. Advanced Sybase DBA Tools
8. Diagnostics & Instrumentation Administration
9. Diagnostics & Instrumentation Reports
10. Examine Configurable
11. Backup Validation
12. Restore
13. Healthcheck <Validation> Summary
0. Exit
Enter your choice: 13
your healthcheck is okay
Enter your choice: 0
sybase@host>
sybase@host> exit
sybase@host> logout
root@host:/#
Do you want to automate running the switch-user and the db_tools? You could perhaps:-
su - sybase -c "echo \"13\n0\" | /var/tmp/db_tools" >> logfile
If you want to add a function to the db_tools scripts, we will need to see the script to know how it is laid out. Hopefully, there is a menu display, an input request and then a case statement, in which case we can add the function easily.
Can you help me out and explain what you are after?
It would be good to know the OS and version as some tools may have differences.
Why not simply modify the db_tools script so that it no longer asks for user input but takes the defaults that you want?
-> Because the db_tools script is the standard for all the user.
But whenever I want t use this script it should take the my inputs i.e 13, 0 and exit.
sybase@host> /var/tmp/db_tools
13
0
exit
You could trying using a heredoc. Or if you need to do something more complex (like verifying responses) then look at expect.
-> heredoc and expect, I am not sure because this is the linux server where I cannot add any expect command tools.
Do you want to automate running the switch-user and the db_tools? You could perhaps:-
1st I want to run the "su - sybase" and then the "/var/tmp/db_tools" and provide the fixed inputs in the same sequence as "13, 0 and exit."
If you want to add a function to the db_tools scripts, we will need to see the script to know how it is laid out. Hopefully, there is a menu display, an input request and then a case statement, in which case we can add the function easily.
-> I dont want to add any finction.
My basic requirement is to run script as follows example :-
I am running below script with root user
#!/bin/bash
cat /etc/hosts
mkdir -p /var/tmp
su - sybase -> upto here no problem
/var/tmp/db_tools -> this should run once I swicth to sybase user
13 -> after running dba_tools I want to enter option 13 everytime
0 -> once option 13 is completed I want to pass 0
exit -> at last I want to enter exit
Thank You all for the reply and my apologies if something is not clear.
So on the menu, where is the EXIT option, and why is it different to option zero?
I should suggest that /var/tmp is not a good place to be storing code. It's the default area used by vi and other tools to store temporary files. Something like your db_tools code would be better under /usr/local/scripts, /usr/local/bin or perhaps /opt/our-apps/scripts and well away from /var