- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Newbie needs help with scripting
Categories
Company
Local Language
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
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
Community
Resources
Forums
Blogs
- 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
11-10-2004 07:45 PM
11-10-2004 07:45 PM
Newbie needs help with scripting
[code]
kk=`date +'%Om'`
if [$kk -eq 1 ]; then
ed=12
else
ed=$((kk-1))
fi
su user1
1resu
. /mnt01/app/admin/pro2000/setup/dbconfig.invoice
. /mnt01/app/invoice/bin/injorabatch -i $ed
echo $ed
[/code]
Now, when I execute this script as "user2", it should switch the user and then execute those 2 programs. However, when I run program as user2 (its name is test) it reacts as follows (ie. there is at least 2 problems in my script):
$ . test
sh: [11: not found.
Password:
If I log in as user1 and run the program, it does as follows:
hp3: $ . test
test: bad pattern: [11 [7]
test: command not found: kk-1 [7]
Password:
hp3: $
I would appreciate any and all advices you may have. Thank you.
- Tags:
- date arithmetic
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-10-2004 08:09 PM
11-10-2004 08:09 PM
Re: Newbie needs help with scripting
First thing is not to keep the script names the same as commands.. So, rename the script as mytest.sh or something other than 'test'.
Secondly, there should be a space in your if statement. It should have read
if [ $kk -eq 1 ]; then
There is a space between [ and $kk in the above if it is not preserved after the posting.
-Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-10-2004 08:47 PM
11-10-2004 08:47 PM
Re: Newbie needs help with scripting
$ . mytest.sh
Password:
hp3: $
Next step are following:
1. script doesn't ask password again.
2. Script executes injorabatch program.
- Tags:
- su
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-10-2004 09:16 PM
11-10-2004 09:16 PM
Re: Newbie needs help with scripting
Not easy if you are doing it as an ordinary user as 'su' will prompt for the password. There are couple of options for you.
1. Use 'sudo' instead of 'su'. You can specify "NOPASSWD" option in sudo configuration file 'sudoers' so it won't ask for password.
2. Write an expect or perl program that will make the interactive su to non-interactive.
Option 1 is easy. But you will need to understand the format of 'sudoers' which is not difficult either. Get it from
http://hpux.cs.utah.edu/hppd/hpux/Sysadmin/sudo-1.6.7p5/
Once it is installed, run the command 'visudo' and add the lines
Cmnd_Alias CMDS = . /mnt01/app/invoice/bin/mybatchjob
login1 ALL = (user1) NOPASSWD: CMDS
The above will enable the login 'login1' to run the program mybatchjob as 'user1' without having to specify the password.
Add all your commands in mybatchjob.
-Sri
- Tags:
- sudo
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-10-2004 09:54 PM
11-10-2004 09:54 PM
Re: Newbie needs help with scripting
Actually, I managed to make it work. I used chmod so that every user can execute that program. Then I executed as user2, and it went through. Problem solved.
Thank you very much of your time and effort, Sri. :)
-Karri Kangas
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-10-2004 09:56 PM
11-10-2004 09:56 PM