LinuxQuestions.org
Visit Jeremy's Blog.
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 09-17-2010, 03:31 PM   #1
BlackCrowe
Member
 
Registered: Aug 2010
Posts: 41

Rep: Reputation: 0
Scripting mount, log gathering, verifying and unmounting


I am trying to piece together some scripts that I've started and some that I've gotten from someone here and modified for my use. I've messed around a bit but 'm not very good at the if then when do. I am getting to do cronjobs for the scripts at intervals but if there is a way to piece this into one script. What I'm trying to do on a weekly basis is.
Any advice would be appreciated.

- Mount a partition to a windows share
- check to see if mounted if mounted do the log gathering
- Gather, tar and zip audit logs and data files and move to the mount point
- remove logs once they are backed up
- remove mapping

The scripts do run individualy so I know they work. The scripts I have are;

Check if mapped if not than map
----------------------------
#!/usr/bin/perl
print `date`;

$ismounted = `df -h |awk '{ print $1 }'|grep ShareName`;

chomp ($ismounted)

unless ($ismounted =~ /ShareName/) {

print "/mnt/dump is NOT mounted!\n";

print "Mounting /mnt/dump...\n";
/opt/temp/scripts/xxxx_dumpsharedcmd_conv.exp`;
} else {
print "/mnt/dump is already mounted.\n";
exit;
}

-----------------------------------------------------
This is the mapping script called in the script above
-----------------------------------------------------

#xxxx_dumpsharecmd_conv.exp
#!/usr/bin/expect

set timeout 20

#set password xxxxxxxxxxx

spawn mount -t cifs //xxx.xxx.xxx.xxx/ShareName/Hostname /mnt/dump -o username=xxxxxx,credentials=dump_cred,iocharset=utf8
,file_mode=0777,dir_mode=0777

#expect "Password:"
#send "$password\r"

expect eof

---------------------------------------------------------------------
This script gathers the logs and data and puts them (for now in a temp dir called /opt/backup but it will be /mnt/dump
--------------------------------------------------------------------

#Logs_Data_Backup

#!/bin/sh
# Logs and Data Backup Script
# This script backups up all of the data to the /opt/backup directory.
# The Administrator will still be required to move this file to
# external media to enable bare-metal restoration of the system.
#
yyyy=`date "+%Y"`
mm=`date "+%m"`
dd=`date "+%d"`
Month=`date "+%b"`
Day=`date "+%e"`
dstr=`date "+%Y%m%d"`

mkdir /opt/backup/Hostname_logs_${dstr}
mkdir /opt/backup/Hostname_data_${dstr}
#
# Log section
#
/bin/tar --create --verbose --preserve \
--ignore-failed-read --gzip -- file=/opt/backup/Hostname_logs_${dstr}/Hostname_logfiles_${dstr}.tgz \
`cat /opt/temp/scripts/backup_dirs-log.txt | xargs` \
>> /opt/backup/Hostname_logs_${dstr}/Hostname_log_filelist.txt
#
# Data section
#
/bin/tar --create --verbose --preserve \
--ignore-failed-read --gzip --file=/opt/backup/Hostname_data_${dstr}/Hostname_datafiles_${dstr}.tgz \
`cat /opt/temp/scripts/backup_dirs-data.txt | xargs` \
>> /opt/backup/Hostname_data_${dstr}/Hostname_data_filelist.txt

echo "Backup complete on " `date` \
>> /backup/filelist.txt

------------------------------------------------------------
This script deletes the logs (this will be the /var/log/audit and /var/log), it's /opt/temp/logs for testing.
This should clean the zipped files out so the next time this runs there will be another weeks worth of accumulated zipped log files to backup.
--------------------------------------------------------------
#delete_backedup_logs*

#!/bin/bash
find /opt/temp/logs/*.gz -exec rm {} \;
 
Old 09-17-2010, 04:03 PM   #2
weibullguy
ReliaFree Maintainer
 
Registered: Aug 2004
Location: Kalamazoo, Michigan
Distribution: Slackware-current, Cross Linux from Scratch, Gentoo
Posts: 2,812
Blog Entries: 1

Rep: Reputation: 259Reputation: 259Reputation: 259
You're using three different scripting languages. You use Perl for the first one, expect for the second, and sh/bash for the last two. The first thing you need to do is decide which one you want to use in your single script and then translate the others. After that, what specifically are you having problems with?

The other option is to write a single script that calls these four in the proper order.
 
Old 09-21-2010, 07:22 AM   #3
BlackCrowe
Member
 
Registered: Aug 2010
Posts: 41

Original Poster
Rep: Reputation: 0
Thanks. The scripts work individually so tying them together is the issue I have comprehending. Picking one scripting language and translating them sounds like fun so the idea of making one script and calling the other script files has crossed my mind. What I'm not sure about is how to tie them together and what to do if somewhere along the way one fails to run.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
unmounting all nfs filesystems without unmounting local ones kaplan71 Linux - General 1 03-05-2009 12:00 PM
Red Hat: Can't mount external hard drives anymore. Was rebooted without unmounting jwhitman Linux - General 5 04-21-2008 06:33 PM
Need help in some scripting related to router information gathering. kharerohit Linux - Networking 1 03-17-2006 11:22 AM
Help in scripting related to router information gathering. kharerohit Linux - Networking 1 03-17-2006 06:37 AM
mount & unmounting a floppy disk swamprat Linux - Newbie 4 09-27-2005 10:25 PM


All times are GMT -5. The time now is 03:03 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration