LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-31-2009, 08:17 PM   #1
sk185094
LQ Newbie
 
Registered: Apr 2009
Posts: 2

Rep: Reputation: 0
Question develop basic sles shell script


I would like to create a few basic shell scripts to automate repeated file copy and set permissions.

Could someone point me in the right direction ?

Here are some of the basic commands I would like to place into a script.

# sum dkmscheck rmkern libbash

17989 6 dkmscheck
08482 2 rmkern
48339 2 libbash

# cp rmkern /opt/gsctools/bin
# chmod 700 /opt/bin/rmkern

# cp dkmscheck /opt/bin
# chmod 700 /opt/bin/dkmscheck

# mkdir –p /opt/lib/shell
# cp libbash /opt/lib/shell
# chmod 700 /opt/lib/shell/libbash
 
Old 08-31-2009, 09:01 PM   #2
kbp
Senior Member
 
Registered: Aug 2009
Posts: 3,790

Rep: Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653
Hi sk185094,

Scripts can be as complex as you like, a couple of things to keep in mind -

- ensure the commands you are running are repeatable or do not require interaction

eg.
Code:
cp rmkern /opt/gsctools/bin
- what happens when the file exists? change to:

Code:
cp -f rmkern /opt/gsctools/bin

- use test conditions to give yourself alternate actions
eg.
Code:
if [ -r /tmp/test ] # is file readable?
then
  echo "File already present"
else
  cp -f /tmp/myfile /tmp/test
fi

- send command output to /dev/null if not required
eg.
Code:
grep test /tmp/myfile > /dev/null 2>&1 # output not required

- you can find the return code of the last command by using '$?'
eg.
Code:
grep test /tmp/myfile > /dev/null 2>&1 # output not required
if [ $? -eq 0 ]
then
  echo "Pattern found in file"
else
  echo "Pattern not found"
fi
Putting your commands in a script:

Code:
#!/bin/bash

sum dkmscheck rmkern libbash > /tmp/my_file_sums_$(date +%F)

cp -f rmkern /opt/gsctools/bin
chmod 700 /opt/bin/rmkern

cp -f dkmscheck /opt/bin
chmod 700 /opt/bin/dkmscheck

mkdir –p /opt/lib/shell
cp -f libbash /opt/lib/shell
chmod 700 /opt/lib/shell/libbash
.. should get you started

cheers,

kbp
 
Old 09-01-2009, 01:48 AM   #3
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,356

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
You may want to bookmark these links:
http://rute.2038bug.com/index.html.gz
http://tldp.org/LDP/Bash-Beginners-G...tml/index.html
http://www.tldp.org/LDP/abs/html/
 
Old 09-02-2009, 08:12 AM   #4
sk185094
LQ Newbie
 
Registered: Apr 2009
Posts: 2

Original Poster
Rep: Reputation: 0
Smile Thanks

Thansk KB, I will give it try.
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Need some help with a basic shell script trist007 Programming 6 07-22-2008 09:22 AM
Basic Shell Script Help Vasquez Linux - Newbie 3 02-28-2005 07:14 PM
basic shell script help lin00b Linux - Newbie 2 10-08-2004 11:32 PM
Basic shell script, please help colly Linux - General 4 10-05-2004 11:24 AM
basic shell script help coyote399 Linux - Newbie 6 04-14-2004 09:22 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:41 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration