Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

read a file (number)

Status
Not open for further replies.

olli2003

Technical User
Jan 31, 2003
93
DE
Hey guys,
I'd like to ask if someone could provide me a little script?

The script should read the first row of a file.

The row (file) looks something like this:
1752 /tmp/adm/test

if the number >1000
then
su - <user>
command -parameter

else
exit

How I can do?
Thanks a lot!
Kind Regards
Oliver
 
Hi

Just [tt]read[/tt] it :
Code:
[b]read[/b] number path [teal]<[/teal] /input/file

[b]if[/b] [teal][[/teal] [i][green]"$number"[/green][/i] -gt [purple]1000[/purple] [teal]][/teal]
[b]then[/b]
    su - <user>
    command -parameter
[b]else[/b]
    [b]exit[/b]
[b]fi[/b]

No idea what you want to do there, but are you sure is not something like [tt]su - <user> -- -c command -parameter[/tt] what you are looking for ?


Feherke.
feherke.ga
 
Hi!
Yes, and thank you very much! It should be something like this. The script owner is the root user, but the command itself should execute by another user.

Kind Regards
Oliver
 
Hi Teks!
I've tried now something like this, but I've got an error:

#!/bin/sh
read number path < /tmp/testoutput
if [ "$number" -gt 10000 ]
then
sudo -u orago1 -H sh -c "cd /sapmnt/GO1/exe/uc/linuxx86_64; brarchive -c -d util_file -cds"
else
exit
fi

Error:
server1/tmp>./testscript2.sh
sh: brarchive: command not found


There is definitely the brarachive program in configured the path. My OS is red hat linux 6.x

Any ideas?

Thanks&Regards
Oliver
 
I'd use the -i option too for the sudo command.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Hi!

like this:
sudo -u orago1 -H sh -i -s "cd /sapmnt/GO1/exe/uc/linuxx86_64; brarchive -c -d util_file -cds"

but just and with this prompt:

sh-4.1$


But nothing was really executed.

Regards
Oliver
 
sudo -u orago1 -H -i sh -c "cd /sapmnt/GO1/exe/uc/linuxx86_64; brarchive -c -d util_file -cds"

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top