How do i check if changes were made to a file using vi


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How do i check if changes were made to a file using vi
# 1  
Old 03-10-2002
How do i check if changes were made to a file using vi

okay, heres the thing

I'm creating a script that I can use to create users. no, this is not a homework assignment or whatever it may seem. i'm just trying to master shell programming.


how can I pass arguments in a file to useradd?????

when i say arguments, I mean, all the arguments and options that is needed to create a user.

I would post my script on here but its just too much to type considering my linux system is installed on a separate hard disk and going back to restart my comp and waiting for it to boot up would be ridiculous

i will post the little bit i remember from the script so if you can help me from the information I supply, please do:

echo -n "Enter user Comment: "
read comment
echo -n "Enter user's home directory: "
read hdirectory
echo -n "Enter user's group: "
read group
echo " "

useradd -c "$comment" -d $hdirectory -g $group

note: (remember, this isn't the whole script)

the question is, how do I save the options and arguments that come after the useradd command in a file and then have the options passed to useradd so useradd can act upon it.

also, how can I have the user go back to the previous prompt when making a user. say, am creating a user using the full version of the script i posted above, how can the user go back to the previous prompt and correct his/her mistake.

to the Admins, Please do not delete or close this thread. THIS IS NOT AN HOMEWORK OR JOB ASSIGNMENT OR ANYTHING THAT GOES AGAINST YOUR POLICY.

THANKS IN ADVANCE
# 2  
Old 03-11-2002
What shell are you using? What OS?

Each time you read a variable, it should be set in that variable
Example (from your script):

echo -n "Enter user Comment: "
read comment

You then use this variable in the useradd command:

useradd -c "$comment" -d $hdirectory -g $group

The $comment should put the information set in the variable comment. If you wanted to put all this into a file (separate it using a character you KNOW will NEVER be in the password file)
then just echo "$user;$comment;$group;$hdirectory" >> myfile

Note the >>. If you use just one > then what ever the last entry is will be the only thing in your file. >> appends to the end of the file.

Post back if I haven't answered all your questions.

And please let me know why you posted a question of how to get information into the comment portion when you had it in your script correctly (using quotes).
thehoghunter
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How do I add a log file path to a vi file to monitor all the changes made to the file?

I'm curious to know how do I add an empty log file (test1.log) to an existing text file to monitor all the changes made to a.txt. Is this expression export PATH=$PATH:/home/test1.log right to be added to the text file a.txt? (5 Replies)
Discussion started by: TestKing
5 Replies

2. Shell Programming and Scripting

Vi : Is it possible to send ctrl + d signal from a file made with vi and executing it.

Hi Experts, Is it possible to send ctrl + d signal from a inside a file made with vi, using Ctrl V , Esc and 004 , escape sequence. Since : 004 should exit the script if executed. Is this something possible. I am trying with vi , I put this code ^ , and trying to execute it but... (4 Replies)
Discussion started by: rveri
4 Replies

3. AIX

How to check changes made in last few weeks?

Hi, I want to know what changes were made to my AIX system in last few weeks/months. Is there any command that I can use for this? I am facing a problem wherein my program which are built few weeks back runs fine but if I build the same program now, it doesn't run as expected. ... (4 Replies)
Discussion started by: shriashishpatil
4 Replies

4. Solaris

Before I delete any file in Unix, How can I check no open file handle is pointing to that file?

I know how to check if any file has a unix process using a file by looking at 'lsof <fullpath/filename>' command. I think using lsof is very expensive. Also to make it accurate we need to inlcude fullpath of the file. Is there another command that can tell if a file has a truely active... (12 Replies)
Discussion started by: kchinnam
12 Replies

5. UNIX for Dummies Questions & Answers

Check the changes made to file in vi

Hi, I use vi editor in Unix. Is there any way if we can know that what change was made to the file opened in vi before quitting? As i opened a huge file made some changes yesterday and didnt save it. Today when i was quitting the vi , i came to know that some changes are made(as i got... (6 Replies)
Discussion started by: kailash19
6 Replies

6. UNIX for Advanced & Expert Users

Check EOF char in Unix. OR To check file has been received completely from a remote system

Advance Thanks. (1) I would like to know any unix/Linux command to check EOF char in a file. (2) Or Any way I can check a file has been reached completely at machine B from machine A. Note that machine A ftp/scp the file to machine B at unknown time. (5 Replies)
Discussion started by: alexalex1
5 Replies

7. Shell Programming and Scripting

strtotime() error - no changes made

Not sure what happened, this page/code always worked before, no changes were made to the code, only the box was powered down, moved and powered back up, the code seems to still be doing its job but spewing out these errors right on the page. Again no changes were made. Warning: strtotime()... (1 Reply)
Discussion started by: ippy98
1 Replies

8. Programming

Problem in reflecting changes made on a JSP File

I make some changes in a JSP file but the changes do not reflect on tomcat server. In my server.xml 'reloadable' paramtere is set to true. I even treid restarting the server. The changes still not reflect. The changes do reflect in a day or two. am not sure why this is happening. Shall... (3 Replies)
Discussion started by: Shikha Agrawal
3 Replies

9. UNIX for Dummies Questions & Answers

monitor changes made by root

Is there any way in Solaris 9 to monitor changes made to user accounts by root? (0 Replies)
Discussion started by: scriptarg
0 Replies

10. UNIX for Dummies Questions & Answers

Script to check for a file, check for 2hrs. then quit

I wish to seach a Dir for a specific file, once the file is found i will perform additional logic. If the file is not found within two hours, i would like to exit. Logically, I'm looking for the best way to approach this Thanks for any assistance in advance. Note: I'm using a C shell and... (2 Replies)
Discussion started by: mmarsh
2 Replies
Login or Register to Ask a Question