Operating System - Linux
1752782 Members
5692 Online
108789 Solutions
New Discussion юеВ

Re: need to create symbolic link

 
pratapvfr
Advisor

need to create symbolic link

Hello friends,
i would looking a small script which can execute through crontab which can check at particular path a symbolic link is present or not if its not present it will create and send email if its present do nothing.

below is the example
here is named net source is /etc/netplug
scrip will execute through crontab and check this sym link is present or not if its not present it will create it and send email to particular users and if its present do nothing..

lrwxrwxrwx 1 root root 12 Jun 15 09:25 net -> /etc/netplug



4 REPLIES 4
Raj D.
Honored Contributor

Re: need to create symbolic link

pratapvfr,

You can create a script and run this script in crontab with particular interval say 15 min:

1. The cron entry would be looks like this:
You can add using $ crontab -e
It will run every 15 min:

15 * * * * /home/dir/sym_link_chk.sh > /dev/null



2. the script :
/hom/dir/sym_link_chk.sh would like this:


#!/usr/bin/sh
# Checking symlink /etc/netplug

EMAIL=email@domain.com

create_and_send_email () {
net_dir=
cd $net_dir
ln -s /etc/netplug net
ls -l net > net_checked.out

cat net_checked.out | mailx -s "symlink created and net_checked OK" $EMAIL
}




[ -L cal_2k ] && echo "OK : Do nothing:" || create_and_send_email

############################################




Enjoy , Have fun!,
Raj.



" If u think u can , If u think u cannot , - You are always Right . "
Raj D.
Honored Contributor

Re: need to create symbolic link

Pratap,
again!,

Correction: cd & Link file name fixed ,





2. the script :
/hom/dir/sym_link_chk.sh would like this:


#!/usr/bin/sh
# Checking symlink /etc/netplug

EMAIL=email@domain.com

create_and_send_email () {
net_dir=
cd $net_dir
ln -s /etc/netplug net
ls -l net > net_checked.out

cat net_checked.out | mailx -s "symlink created and net_checked OK" $EMAIL
}




cd
[ -L net ] && echo "OK : Do nothing:" || create_and_send_email

################################################



* Remember to asign points once resolved and before closing the thread.. Cheers.
" If u think u can , If u think u cannot , - You are always Right . "
Steven Schweda
Honored Contributor

Re: need to create symbolic link

> ls -l net > net_checked.out

I'd probably do something more like:

temp_file="/tmp/net_$$_checked.out"

echo 'Created link:' > $temp_file
pwd >> $temp_file
ls -l net >> $temp_file
date >> $temp_file

[Send the e-mail message...]

rm $temp_file


> * Remember to asign points [...]

Don't forget to deduct points for errors.
Raj D.
Honored Contributor

Re: need to create symbolic link

Steven,

> * Remember to asign points [...]
>> Don't forget to deduct points for errors.


You are a cool admin, appreciate it..!


(0 pts. for this pls.)
" If u think u can , If u think u cannot , - You are always Right . "