The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Find a path of a specific file samir_standing Shell Programming and Scripting 11 10-29-2008 07:19 PM
Change Specific Line of a File msb65 UNIX for Dummies Questions & Answers 10 08-20-2008 10:18 PM
How to change a specific character in a file sdubey Shell Programming and Scripting 6 02-22-2008 03:30 PM
Script to delete logs or take backups under specific user namishtiwari Shell Programming and Scripting 12 01-25-2008 06:31 AM
Delete specific lines in a text file dniz High Level Programming 9 08-08-2005 08:30 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 12-02-2008
Great Uncle Kip Great Uncle Kip is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 14
Script to change/find/delete/install a specific file

Hi

Very much a newbie to UNIX & scripting, but have identified an area within work that would benefit from being automated, as its repeated manually very often, and it looks like the ideal first script!

What I need to do is change directory to a users home (cd ~), and then find and remove a specific file (in the format .abcd).

The final part of my script will then be to unpack a cpio package to the users home path.

Although I know the basic Unix commands to do this step by step, i'm unsure as to how this can be interpreted into a shell, to run it automatically.

Any advice would be hugely appreciated.
  #2 (permalink)  
Old 12-02-2008
vbe's Avatar
vbe vbe is offline Forum Staff  
Moderator
  
 

Join Date: Sep 2005
Location: Switzerland - GE
Posts: 1,568
Well,
There is only one way to find out:
Try...
Quote:
Although I know the basic Unix commands to do this step by step, i'm unsure as to how this can be interpreted into a shell, to run it automatically.
For a start, you could type echo "Im starting my test"
then using your knowledge, execute step by step what is to be done
echo "Ive finished".
If the lot was successfull, you have now in your .sh_history between the 2 markers (echo...) the code needed for your script, copy paste in a new file called test.sh (or whatever you like...) make that file executable: chmod 755 test.sh
use it!
./test.sh
  #3 (permalink)  
Old 12-12-2008
Great Uncle Kip Great Uncle Kip is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 14
Thanks very much vbe.

This is what I have so far-

cd ~
~/.mozilla
ls -a
echo "Do you wish to remove and re-install the .mozilla profile? Y/N"
read answer
echo "The answer is $answer"
exit 1
rm -rf .mozilla
cpio -icvdum < /pcms/data/mozilla_install.cpio
echo "Mozilla has been re-installed "

What I need to do now is get it so that if the answer to the echo is "Y", then the script continues (to remove the .mozilla), if not, to exit the script?

Regards
Kip
  #4 (permalink)  
Old 12-12-2008
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,944
here is a sample

Code:
read a; if [ $a = "Y" ]
then
echo "continue"
else
echo "exit"
fi
  #5 (permalink)  
Old 12-17-2008
Great Uncle Kip Great Uncle Kip is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 14
All the help so far has been cracking, cheers all!

One last thing i'm just wondering.....

Is there a command where I can check if a directory exists, before removing it? If it does, I want the script to remove it and the proceed to the reinstall. If not, I want it to create it and proceed to the install?

Regards
Kip
  #6 (permalink)  
Old 12-20-2008
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,944
Quote:
Originally Posted by Great Uncle Kip View Post
All the help so far has been cracking, cheers all!

One last thing i'm just wondering.....

Is there a command where I can check if a directory exists, before removing it? If it does, I want the script to remove it and the proceed to the reinstall. If not, I want it to create it and proceed to the install?

Regards
Kip
Code:
if  [  -d $dir_name ]
then
  echo "dir $dir_name is available"
else
  echo "dir $dir_name is not available"
fi
  #7 (permalink)  
Old 01-07-2009
Great Uncle Kip Great Uncle Kip is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 14
Thanks for all the help, got the script up and running, tested, and it works fantastic!
Closed Thread

Bookmarks

Tags
shell script, shell scripting, unix commands, unix scripting, unix scripting basics

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 12:01 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0