Operating System - HP-UX
1822193 Members
3766 Online
109640 Solutions
New Discussion юеВ

how to add fstab entry using script

 
apple
Super Advisor

how to add fstab entry using script

dear hpux gurus,
would like to seek your advice. ive created few file systems. but sir, how can i create script so that i can add the entry inside fstab using .ksh script. hope to hear from you. appreciate your can share any advice to perform system administration faster. many thanks in advance. Thank You.
12 REPLIES 12
Dennis Handly
Acclaimed Contributor

Re: how to add fstab entry using script

Why wouldn't you just edit fstab manually for the few filesystems?
Just copy the format of existing lines.
Vijay Dsouza
Frequent Advisor

Re: how to add fstab entry using script

Hi Almond,

yest makes sence on what is said because you are not going to create filesystems regularly.

Just edit the /etc/fstab file through vi editor and place the entries required

ie :

/dev/vgname/lvol1 /mountpoint vxfs delaylog 0 3
/dev/vgname/lvol1 /mountpoint vxfs delaylog 0 2
/dev/vgclnpdb/lvol1 /mountpoint vxfs delaylog 0 1 .

Davis Paul
Valued Contributor

Re: how to add fstab entry using script

Hi almond08
Please have the attached file.

James R. Ferguson
Acclaimed Contributor

Re: how to add fstab entry using script

HI:

Learn to use 'vi'.

If you have need to programatically add entries to '/etc/fstab' all that is needed is something like this, at a shell command line:

# echo "/dev/vg02/lvol1 /patches vxfs rw,suid,largefiles,delaylog,datainlog 0 2" >> /etc/fstab

Regards!

...JRF...
SKR_1
Trusted Contributor

Re: how to add fstab entry using script

Only vi is the best option, it will take less time than that of any scripts.

So go for using vi editor only.

Thanks

SKR
Deepak Kr
Respected Contributor

Re: how to add fstab entry using script

Hi,

Even through you can use following in script:

#cp -p /etc/fstab /etc/fstab.bak
# echo "/dev/vg02/logical volume /mount point vxfs rw,suid,largefiles,delaylog,datainlog 0 2" >> /etc/fstab
#diff /etc/fstab /etc/fstab.bak

but using VI directly is always better option.

Cheers!!
Deepak
"There is always some scope for improvement"
Tim Nelson
Honored Contributor

Re: how to add fstab entry using script

echo "/dev/vgname/lvol1 /mountpoint vxfs delaylog 0 3" >> /etc/fstab


Grayh
Trusted Contributor

Re: how to add fstab entry using script

for example to add a entry like the one below
/dev/fd0 /media/floppy auto rw,noauto,user,sync 0 0

I always prefer vi.. to make life simpler
V. Nyga
Honored Contributor

Re: how to add fstab entry using script

Sorry for bringing this up again, but why nobody gives him a simple answer?

When I have to add several equal directories (for example nfs-mounted) to several workstations, I use a script.
My sh-script contains:

cat >>/etc/fstab
mkdir
mount -a
bdf

my contains (nfs-mounted from another server):

: nfs rw,bg,hard 0 0

You can add several lines without problems.

For an internal dir you should use:

/dev/vg01/lvol6 /archiv vxfs rw,suid,largefiles,delaylog,datainlog 0 2

HTH
Volkmar
*** Say 'Thanks' with Kudos ***
Srimalik
Valued Contributor

Re: how to add fstab entry using script

>cat >>/etc/fstab
>mkdir
>mount -a
>bdf

How do these commands help????
why would somebdy want to do this kind of thing?

Why won't you just vi /etc/fstab and type whatever you typed in .

One scenario I can think where you need a script to append to /etc/fstab is:
you have a script which creates multiple filesystems. ( I wrote a script while preparing a setup with 1000+ mounted filesystems).

The script will these tasks:

1) create a LV ( append a number after each LV name and go on incrementing the number each time)
2) mkfs
3) create mount point ( with the number appended)
4) mount the newly created FS
5) add entry in /etc/fstab so that the mounts are done during a reboot.


abandon all hope, ye who enter here..
TTr
Honored Contributor

Re: how to add fstab entry using script

I agree that modifying /etc/fstab with a script is asking for trouble. But when dealing with several entries at once and more than one server it is OK to do it.

I would add that whenever you add lines to /etc/fstab, sanitize them first by using "mount -V". You could also test their syntax by trying to mount the new entries by using the mountpoint only such as "mount /newdir".
Doug O'Leary
Honored Contributor

Re: how to add fstab entry using script

Hey;

While editing the fstab file is an option, I'm not sure we can say it's always preferable. Occasionally, I'm tasked with generating a new system that looks like an old system - migration, update, etc. Some of these source systems have hundreds of filesystems that are changed by one or two characters from their source counterparts. This is something that just begs for a script.

If, however, you're not facing something like this, you probably want to edit the fstab file. Relying on script will limit an admin's growth potential.

The scripts that I use, generally inline, all use a datafile. The datafile will look like:

${vg} ${lv} ${mp}|${owner}

For example:
vgSAP sapmnt 2048 /sapmnt/INST
vgsap oracle 4096 /oracle
vgsapdata ora_data1 8192 oraINST:dba

The logic is fairly straight forward - which is why this tends to be rewritten on the fly all the time:

cat ${table} | while read vg lv size mp
do
echo "############################"
printf "%-20s %-35s %8d %s\n" ${vg} ${lv} ${size} ${mp}
lvcreate -L ${size} -n ${lv} ${vg}
echo ${mp} | grep ":" > /dev/null 2>&1
if [ $? -ne 0 ]
then
[[ ${size} -gt 2048 ]] && args="-o largefiles" || args=""
newfs -F vxfs ${args} /dev/${vg}/r${lv}
[[ ! -d ${mp} ]] && mkdir -p -m 755 ${mp}
[[ ${size} -gt 2048 ]] && args=",largefiles" || args=""
echo "/dev/${vg}/${lv} ${mp} vxfs delaylog${args} 0 2" >> /etc/fstab
mount ${mp}
else
chown ${owner} /dev/${vg}/r${lv}
fi
done

Doing something like this makes a complete filesystem reorg take minutes vs hours if doing by hand or days if doing by sam.

On more than one occasion, scripts like this have made DR exercises succesful where they otherwise would have failed.

Doug

------
Senior UNIX Admin
O'Leary Computers Inc
linkedin: http://www.linkedin.com/dkoleary
Resume: http://www.olearycomputers.com/resume.html