Backup script assistance - filename prompt


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Backup script assistance - filename prompt
# 1  
Old 01-04-2014
Backup script assistance - filename prompt

I am new to this forum, so please go easy on me Smilie

I created a basic script to backup my router, which runs a linux firmware called OpenWrt. The script uses dd to image the router's RAM blocks, copy's the file to local usb storage, and then uploads it to a remote ISP personal ftp account. What I would like to happen though is that instead of manually naming the .bin file (router image) in the script, I would like the script to prompt to name the file before the dd, cp, and ftp upload process.

Here is the script that I created for a better understanding:

Code:
#!/bin/sh
cd /tmp
rm *.bin

****Prompt to name the bin file at this stage, and then continue with the remainder of the script processes*****

dd if=/dev/mtd0 of=/tmp/ask-for-file-name.bin
dd if=/dev/mtd1 of=/tmp/ask-for-file-name.bin
dd if=/dev/mtd2 of=/tmp/ask-for-file-name.bin
dd if=/dev/mtd3 of=/tmp/ask-for-file-name.bin
dd if=/dev/mtd4 of=/tmp/ask-for-file-name.bin
dd if=/dev/mtd5 of=/tmp/ask-for-file-name.bin
cd /mnt/150GB/openwrt-backup
rm *.bin
cd /mnt/32GB/openwrt-backup
rm *.bin
cd /mnt/8GB/openwrt-backup
rm *.bin
cp -Rv /tmp/ask-for-file-name.bin /mnt/150GB/openwrt-backup
cp -Rv /tmp/ask-for-file-name.bin /mnt/32GB/openwrt-backup
cp -Rv /tmp/ask-for-file-name.bin /mnt/8GB/openwrt-backup
wput -v -u -R username:password@ftpserver:21/router/images/ask-for-file-name.bin
cd /tmp
rm *.bin

Thanks in avance for those that can help me out.

Last edited by bartus11; 01-04-2014 at 10:07 AM.. Reason: Please use code tags instead of quote tags
# 2  
Old 01-04-2014
Give name in the command line => You can give the name or caller script can give the name.
Code:
#!/bin/sh
# cmd somename

name="$1"

# if name is empty = exit
[ "$name" = "" ] && echo "usage:$0 name" >&2 && exit 1


cd /tmp
rm -f *.bin 2>/dev/null

dd if=/dev/mtd0 of=/tmp/"$name.0.bin"
#...

# 3  
Old 01-05-2014
Thank you for your input. However, what I'm looking for is for the script to prompt to enter the in a desired file name for the backup file instead of specifying the filename right in the script.
# 4  
Old 01-05-2014
Quote:
Originally Posted by kgoerbig
I am new to this forum, so please go easy on me Smilie

I created a basic script to backup my router, which runs a linux firmware called OpenWrt. The script uses dd to image the router's RAM blocks, copy's the file to local usb storage, and then uploads it to a remote ISP personal ftp account. What I would like to happen though is that instead of manually naming the .bin file (router image) in the script, I would like the script to prompt to name the file before the dd, cp, and ftp upload process.

Here is the script that I created for a better understanding:

Code:
#!/bin/sh
cd /tmp
rm *.bin

****Prompt to name the bin file at this stage, and then continue with the remainder of the script processes*****

dd if=/dev/mtd0 of=/tmp/ask-for-file-name.bin
dd if=/dev/mtd1 of=/tmp/ask-for-file-name.bin
dd if=/dev/mtd2 of=/tmp/ask-for-file-name.bin
dd if=/dev/mtd3 of=/tmp/ask-for-file-name.bin
dd if=/dev/mtd4 of=/tmp/ask-for-file-name.bin
dd if=/dev/mtd5 of=/tmp/ask-for-file-name.bin
cd /mnt/150GB/openwrt-backup
rm *.bin
cd /mnt/32GB/openwrt-backup
rm *.bin
cd /mnt/8GB/openwrt-backup
rm *.bin
cp -Rv /tmp/ask-for-file-name.bin /mnt/150GB/openwrt-backup
cp -Rv /tmp/ask-for-file-name.bin /mnt/32GB/openwrt-backup
cp -Rv /tmp/ask-for-file-name.bin /mnt/8GB/openwrt-backup
wput -v -u -R username:password@ftpserver:21/router/images/ask-for-file-name.bin
cd /tmp
rm *.bin

Thanks in avance for those that can help me out.
Your request is confusing.

Do you want the script to prompt for the single filename to replace /tmp/ask-for-file-name.bin?

Why does the user need to enter a filename at all? Why shouldn't the script create its own filename (indicating the date and time of the backup) without involving the user? Do you think the user is going to need to specify a directory other than /tmp to hold the temporary file? (If so, removing /tmp/*.bin at the end of the script also needs to be changed!)

If the script has to be given the filename for some reason, is there a reason why the user can't give the filename as a command line operand as suggested by kshji? Would you like the script to accept a command line operand as the temporary filename, but to prompt for it if no operand is given?

Do you realize that your backup of /dev/mtd1 overwrites your backup of /dev/mtd0, your backup of /dev/mtd2 overwrites your backup of /dev/mtd1, your backup of /dev/mtd3 overwrites your backup of /dev/mtd2, your backup of /dev/mtd4 overwrites your backup of /dev/mtd3, and your backup of /dev/mtd5 overwrites your backup of /dev/mtd4? So the only thing this script backs up is /dev/mtd5.

Why is your script removing all filenames ending with .bin from /tmp? Why not just remove the file you created?

I assume that you realize that since you never check for errors, any failed backup will cause all backups to be destroyed. Wouldn't it be better to keep your previous backup at least until you have confirmed that your new backup completed successfully and was successfully copied to the corresponding backup directory?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need assistance in ksh script

requirement : I need to read a text file and find out which particular line has highest charcters on it using the shell script. I tried & was able to find out only for one line. I could not able to find out for the entire the line. sed -n '10 p' ctstest.sh | wc -w Please guide me... (5 Replies)
Discussion started by: ramkumar15
5 Replies

2. UNIX for Dummies Questions & Answers

Filename collision during backup

Hi, I am trying to backup all *.tar files from a legacy Linux to a portable harddrive. find . -name "*.tar" -exec cp {} /media/mypassport/backup \; I found that there are files with the same filenames and they were overwritten in the destination folder. They are coming from different... (4 Replies)
Discussion started by: cornellhumphrey
4 Replies

3. Shell Programming and Scripting

Help with Backup Shell Script for Network Device Configuration backup

HI all, im new to shell scripting. need your guidence for my script. i wrote one script and is attached here Im explaining the requirement of script. AIM: Shell script to run automatically as per scheduled and backup few network devices configurations. Script will contain a set of commands... (4 Replies)
Discussion started by: saichand1985
4 Replies

4. Shell Programming and Scripting

Dummy script assistance

Hi, I am new in ksh scripting and if anyone can help that would be great. I'm writing a script which will SSH to several machines and then would append a certain file from a NAS to the /etc/sudoers file the problem i am having is after the script connects to a certain server the commands are... (7 Replies)
Discussion started by: galuzan
7 Replies

5. Shell Programming and Scripting

Need assistance with a simple script

I have a simple script. Do you know what I got this error? ./total_memory.ksh: line 5: ' Thanks #! /bin/bash setmem=30177660 totalMemory= grep MemTotal /proc/meminfo | awk '{print $2}' if ; then echo "Total memory $totalMemory is less than :$setmem" exit 1 ... (3 Replies)
Discussion started by: Beginer0705
3 Replies

6. Shell Programming and Scripting

script assistance with shift J

Hey all, I need some assistance. I'm writing a script to eject tapes from a tape library, but the library is not a queued system and can only eject 15 tapes at a time. I added paste -d : -s so that it goes through full_tapes and puts each media_id on one line separated by the :. Now I'm... (2 Replies)
Discussion started by: em23
2 Replies

7. Shell Programming and Scripting

shell script assistance please

When I run this command (showstatus <username> <dbname>) in the prompt, the following will be displayed in the screen: 1. Show processes 2. Start process 3. Stop process 4. Go back to prompt Once i choose/type Option "1" (which is Show processes), it will display the list of processes... (5 Replies)
Discussion started by: xinoo
5 Replies

8. Shell Programming and Scripting

need assistance ----SH schell script

Hello All, I need to develop a script(SH]) to generate a comparison file between two files old and new file.The script takes in parameter the old file path and the new file path. And the script generates a file containing the comparison between the two files with this details: - Keys... (2 Replies)
Discussion started by: shahidbakshi
2 Replies

9. Shell Programming and Scripting

Need a little assistance with a shell script

I need to modify a script to send an attatched file. I have researched and read the faq's but have not found a solution for my script. Here is a copy of the code I am using: #!/bin/sh mysqldump --opt --skip-add-locks --user=****** --password=******* databasename | gzip >... (3 Replies)
Discussion started by: rickou812
3 Replies

10. Shell Programming and Scripting

KSH Script Assistance

Hey everyone, I'm newer than new when it comes to this ksh and scripting stuff, and unix in general. I have been thrown into a task at work that A: They expect me to come up to speed on, B: Show I can do this. (Program for the workgroup) Here's the script, part of it, from the overall... (3 Replies)
Discussion started by: Brusimm
3 Replies
Login or Register to Ask a Question