how to run script? call other script? su to another user? make a cron?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to run script? call other script? su to another user? make a cron?
# 1  
Old 05-04-2009
Java how to run script? call other script? su to another user? make a cron?

Good morning. I am searching for "how-to"'s for some particular questions:

1. How to write a script in HP-UX 11.

2. How to schedule a script. [using cron job.]

3. How to "call" scripts from the original script.

4. How to su to another user from within a script.

This is the basics of what the script should do.
su to a user
go to a specific directory
execute a process to stop a driver,
then another process to start a driver
exit su
begin the same as above, for the next user, and so on.


[I know the gist of the steps, because I do them from command line, but I
consulted with a person who works here, and he said you can't just script
the exits all in one file, because it'll make the script quit. My idea, is that
if we could somehow have the script call other scripts, that would work,
right? I hope that you gurus can assist lil 'ol me]

I need a script that does this:

1. call a second script, that does this:

2. su to user_x
3. cd to a specific directory
4. run a specific process to stop a driver [process already made, only
user_x can run it]
5. run a specific process to start a driver [process already made, only
user_x can run it]
6. exit [to quit out of su for user_x]

7. call a third script, that does this:

8. su to user_y
9. cd to a specific directory
10. run a specific process to stop a driver [process already made, only
user_y can run it]
11. run a specific process to start a driver [process already made, only
user_y can run it]
12. exit [to quit out of su for user_y]

13. call a fourth script, that does this: (you probably know where I'm
going with this by now ...)

14. su to user_z
15. cd to a specific directory
16. run a specific process to stop a driver [process already made, only
user_z can run it]
17. run a specific process to start a driver [process already made, only
user_z can run it]
18. exit [to quit out of su for user_z]

19. end of script

20. schedule script to run every morning at 5:30 AM using cron

I had looked around the forum, and I think I could do this so far:

script name: startdriver.sh

and it calls other scripts (something like this)

startdriver1.sh && startdriver2.sh && startdriver3.sh

I hope that someone can assist me. I don't know the syntax for writing
the scripts. I know the manual commands to type in during a session, but
not the scripting.

I know that we use HP-UX, and that we use cron for scheduling jobs.

I wish that I was more help.

If you need more information prior to assisting me, please give me a
command I can run to find out that information.

[I don't normally do Unix work. I want the script so that I don't have to
manually type in the commands.]

If this forum is not the proper place for a beginner such as myself, please
direct me to the proper forum.

Thanks!
# 2  
Old 05-04-2009
And if the second script fail the others are never called?

Why not simply have a script for each user called by root cronfile?
Then the syntax would be in the cron file:
su - <user> -c <your_users_script>
# 3  
Old 05-04-2009
Quote:
Originally Posted by instant000
Good morning. I am searching for "how-to"'s for some particular questions:
Please don't post homework's, post reported, see The UNIX and Linux Forums - Forum Rules
Use the search box on top right corner if you want to find the answers.
# 4  
Old 05-04-2009
Java

Quote:
Originally Posted by vbe
And if the second script fail the others are never called?

Why not simply have a script for each user called by root cronfile?
Then the syntax would be in the cron file:
su - <user> -c <your_users_script>
Actually, if any of the three scripts fail, the process fails.

I'm asking because I don't know how to do this.

This is what I know how to do:

su <username>
cd /path/path/path/path
driver1.stop
driver1.start
exit
su <username2>
cd /path/path/path
driver2.stop
driver2.start
exit
su <username3>
cd /path/path/path
driver3.stop
driver3.start

Are you saying that I can schedule them independently of each other?

Due to the nature of the program (drivers for some program to tie into a database), I am not sure if I can do them, except in this order.
# 5  
Old 05-04-2009
Quote:
Originally Posted by danmero
Please don't post homework's, post reported, see The UNIX and Linux Forums - Forum Rules
Use the search box on top right corner if you want to find the answers.
No homework permitted in the forums. Thanks.
# 6  
Old 05-04-2009
Reopened thread. User provided office email (not homework).

Please continue.
# 7  
Old 05-05-2009
Create a user.list file having the user.name , stop command and start command.
Code:
# cat <<eof>>user.list
user1 /path/to/user1/stop.proccess /path/to/user1/start.proccess
user2 /path/to/user2/stop.proccess /path/to/user2/start.proccess
eof

Use a loop to read from user.list and to test(echo) each command.
Code:
# while read user stop start
    do 
       echo su $user
       echo $stop
       echo $start
       echo exit
    done < user.list

The output will be:
Code:
su user1
/path/to/user1/stop.proccess
/path/to/user1/start.proccess
exit
su user2
/path/to/user2/stop.proccess
/path/to/user2/start.proccess
exit

When you have everything as you like , just remove the echo on your loop.

Success.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script run in a case statement call to run a php file, also Perl

Linux System having all Perl, Python, PHP (and Ruby) installed From a Shell script, can call a Perl, Python, PHP (or Ruby ?) file eg eg a Shell script run in a case statement call to run a php file, also Perl or/and Python file??? Like #!/usr/bin/bash .... .... case $INPUT_STRING... (1 Reply)
Discussion started by: hoyanet
1 Replies

2. Shell Programming and Scripting

Bash script from makefile - it is called each time i call make

I've created a tag in the makefile: mytag: $(shell ${PWD}/script.sh) When i do: make clean - the script is executed When i perform make or make mytag the script is again executed with the output: make: Nothing to be done for mytag What i want ? I want script.sh to be executed only... (0 Replies)
Discussion started by: Pufo
0 Replies

3. AIX

Commands to call script work from command line but not from Cron entry

My first post evidently did not materialize so I posted it again: Runnning a cron job every 5 mins to send data files to a state facility. My original cron entry at worked fine: 01,06,11,16,21,26,31,36,41,46,51,56 * * * * /home/sftpuser/stateinoc-from-appname.ksh Somewhere I have a... (1 Reply)
Discussion started by: Skyybugg
1 Replies

4. Shell Programming and Scripting

Run script through cron with user environment variables

Hi everyone, I wrote a script that is supposed to be run by cron on a daily basis. It works just fine if I run it manually, but due to a lack of environment variables (which are available during my user session but not when cron runs the script) it keeps failing to run successfully. Here's the... (2 Replies)
Discussion started by: gacanepa
2 Replies

5. Shell Programming and Scripting

help to make script run recursively

I have this little bash script I use to transcode mkv files using handbrake. #!/bin/bash sourcedir="/media/raid10/video/to_be_encoded_series" destdir="/media/raid10/video/series" cd "$sourcedir" for i in *.mkv; do HandBrakeCLI -i "$i" -o "$destdir/${i%.*}.mkv" -e x264 -q 20.0 -E copy -B... (4 Replies)
Discussion started by: barrydocks
4 Replies

6. Shell Programming and Scripting

how we can make shell script not to run

Hi,shell script is scheduled from maestro and we want mastero should not run shell script so can we edit the shell script so that it should run.ThanksPrakash (5 Replies)
Discussion started by: prakashdba2010
5 Replies

7. Shell Programming and Scripting

howto run remotely call function from within script

Hi I have the following script : #!/bin/ksh #################### Function macAddressFinder ######################## macAddressFinder() { `ifconfig -a > ipInterfaces` `cat ipInterfaces` } ####################################################################### # # print... (2 Replies)
Discussion started by: presul
2 Replies

8. UNIX for Dummies Questions & Answers

shell script run by user or cron job ?

My shell script runs fine both as a cron job and when i issue it. However, I wish to differentiate when it runs as a cron-job so the "echo" statements are not issued (they get mailed to me, which i don't want). I tried checking $USER but since the cron was created in my user that does not... (5 Replies)
Discussion started by: sentinel
5 Replies

9. Shell Programming and Scripting

Can anyone make this script run faster?

One of our servers runs Solaris 8 and does not have "ls -lh" as a valid command. I wrote the following script to make the ls output easier to read and emulate "ls -lh" functionality. The script works, but it is slow when executed on a directory that contains a large number of files. Can anyone make... (10 Replies)
Discussion started by: shew01
10 Replies

10. Shell Programming and Scripting

Call shell script from php not run ?

Hi. I write a shell script for import data to oracle using sql loader. I set permission 755 or 777 for that script. I can run that script in the consol okay. When I call it from PHP using system command. I got return value 126 this value when don't have permission right ? I check step... (2 Replies)
Discussion started by: raccsdl
2 Replies
Login or Register to Ask a Question

Featured Tech Videos