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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating a script in VI

Status
Not open for further replies.

Unixdunce

Technical User
Nov 29, 2006
4
US
yes we're tying to create a script that asks the user weather or not they want to delete files in a /var/audit folder if they answer yes then to rm -rf * if no to exit. If they answer yes we want to then show them the folder is empty and ask if they want to shutdown. If they say yes we want the shutdown -y -i0 -g0 to run and let them no and if they select no to exit back to the command prompt. Any and all help is appreciated thank you.
 
Hi

Code:
echo "Delete ?"
read ans
test "$ans" == "yes" && {
  rm -rf /var/audit/*
  ls /var/audit/
  echo "Shutdown ?"
  read ans
  test "$ans" == "yes" && shutdown -y -i0 -g0
}
Tested with [tt]bash[/tt] and [tt]ksh[/tt].

I am puzzled with the [tt]vi[/tt]... Why is it mentioned in the subject...

Feherke.
 
Yes we only have the VI edit available to us on our platform. We have do use vi filename.sh and edit our file. We put in the above suggested and we get test: operator unkown. If you or anyone else has any suggestions for a vi script for our problem, we appreciate the help.
 
Hi

Could you tell us more about your operating system and shell ?

In meantime you may try to change the [tt]test[/tt] into [tt][[/tt] and use [tt]if[/tt] :
Code:
echo "Delete ?"
read ans
[red]if [[/red] "$ans" == "yes" [red]]; do[/red]
  rm -rf /var/audit/*
  ls /var/audit/
  echo "Shutdown ?"
  read ans
  [red]if [[/red] "$ans" == "yes" [red]]; do[/red]
    shutdown -y -i0 -g0
  [red]done[/red]
[red]done[/red]

Feherke.
 
Sounds a bit like homework to me.....

Mike

"Whenever I dwell for any length of time on my own shortcomings, they gradually begin to seem mild, harmless, rather engaging little things, not at all like the staring defects in other people's characters."
 
To avoid unknown operator messages, replace all:
test "$ans" == "yes"
with:
test "$ans" = "yes"

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
I tend to agree with Mike. Why would anyone eant to shutdown within a script of this kind?

Alan Bennett said:
I don't mind people who aren't what they seem. I just wish they'd make their mind up.
 
This as Sun Unix OS on an airborne platform. We run into a problem every few days where all the logins are stored into cach in /var/audit and we have to go in as admin for users to delete and restart. We were/are trying to create a simple script that they can run that gives them the option to delete cache and then shutdown the unit if they wanted to restart at that time. We thank you for all your help and any inputs you provide and have provided.










 
If you could explain how to do that we would appreciate it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top