HPE GreenLake Administration
- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- su command with expect script
Operating System - Linux
1828293
Members
2746
Online
109975
Solutions
Forums
Categories
Company
Local Language
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
back
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-14-2008 09:43 PM
10-14-2008 09:43 PM
su command with expect script
Hi All!
I need to automate the su command using expect script.Suppose I login as a user A , I need to change the user to oracle using the su oracle command and execute the command "sqlplus -ver".
I tried writing a expect script for the same , but can't figure out the reason it is not working.
Can someone please help. Below is the expect script that I wrote:
#!/usr/bin/expect -f
set timeout -1
spawn /bin/su oracle -c date
expect "Password: "
send "oracle\r"
expect "\r\n"
send "sqlplus -ver\n"
I need to automate the su command using expect script.Suppose I login as a user A , I need to change the user to oracle using the su oracle command and execute the command "sqlplus -ver".
I tried writing a expect script for the same , but can't figure out the reason it is not working.
Can someone please help. Below is the expect script that I wrote:
#!/usr/bin/expect -f
set timeout -1
spawn /bin/su oracle -c date
expect "Password: "
send "oracle\r"
expect "\r\n"
send "sqlplus -ver\n"
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2008 11:37 AM
10-15-2008 11:37 AM
Re: su command with expect script
Probably you don't need expect for this. You only need SUDO. Give SUDO a try.
Por que hacerlo dificil si es posible hacerlo facil? - Why do it the hard way, when you can do it the easy way?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2008 09:08 PM
10-15-2008 09:08 PM
Re: su command with expect script
Yes I thought about the sudo option. But that means I would have to make an entry in the /etc/sudoers file.Since the application I am developing has a constraint that no changes should be made to the file system on the server, I cannot use the sudo option.
Please let me know if you need anymore information on this.
Thanks!
Rohit Khaladkar
Please let me know if you need anymore information on this.
Thanks!
Rohit Khaladkar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-17-2008 03:49 AM
10-17-2008 03:49 AM
Re: su command with expect script
The su command in your expect script is "/bin/su oracle -c date", which means only the command "date" is executed as user "oracle". After that, the su session will not accept further commands: the su session will simply end.
You should be doing something like:
#!/usr/bin/expect -f
set timeout -1
spawn /bin/su oracle -c "sqlplus -ver"
expect "Password: "
send "oracle\r"
expect "\r\n"
# add here suitable expect lines to catch the entire sqlplus -ver output
MK
You should be doing something like:
#!/usr/bin/expect -f
set timeout -1
spawn /bin/su oracle -c "sqlplus -ver"
expect "Password: "
send "oracle\r"
expect "\r\n"
# add here suitable expect lines to catch the entire sqlplus -ver output
MK
MK
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
Company
Support
Events and news
Customer resources
© Copyright 2025 Hewlett Packard Enterprise Development LP