Bash Scripting - Waiting for a certain amount of data
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Bash Scripting - Waiting for a certain amount of data
Short version: Anyone know a way to script a file copy so that x amount of data copies to a location, flushes, and the copy resumes to gather x amount of data again?
We're implementing a DVD system to backup fiels on remote servers. The way the DVD system archives data is this:
Data is put into a cache directory of the local machine, then moves the data onto DVD. If the amount of data going into the cache outstips the amount of data going out of the cache, the copy times out. Due to disk space limitations, I've only got about 20GB of cache space available to give the DVD system, but I've got 80+ GB of data on various servers.
The directory structure is too fragmented to parse the directories in a reference file. (18,000 directories on server, for example) I've figured out the while statement (code follows) to check the parameters of the cache, but can't figure a way to limit the initial data copy until the system is done archiving.
Script:
#!/bin/sh
SERVERLIST_FILENAME="serverlist.txt"
DELAY_THRESHOLD=0
DELAY_TIME="60s"
DELAYED_EVENTS=99999
poll_for_mmparam_delayedevents() {
echo I am polling right now.... I am waiting a really long time...
DELAYED_EVENTS=`mmparam TEST | grep "Number of delayed events:" | awk '{print $5}'`
sleep $DELAY_TIME
}
for BACKUP_PATH in `cat $SERVERLIST_FILENAME | grep -v "^#"`
do
SOURCE_PATH=`echo $BACKUP_PATH | awk -F : '{print $1}'`
DESTINATION_PATH=`echo $BACKUP_PATH | awk -F : '{print $2}'`
echo I am backing up $SOURCE_PATH to $DESTINATION_PATH
cp -RPd $SOURCE_PATH $DESTINATION_PATH
# Wait in loop until delayed events are all processed. Only
# then should we move on to copy the next server.
while [ $DELAYED_EVENTS -gt $DELAY_THRESHOLD ]
do
poll_for_mmparam_delayedevents
done
# reset to avoid a potential race-condition
DELAYED_EVENTS=99999
done
I just hacked up this C program that I think will do what you need.
It takes three parameters. The source directory, the destination directory and the size you want to pause at. IMPORTANT: Make sure that the dest directory is not in the source tree.
When the program has copied x amount of data to the destination it will pause until it gets a SIG_HUP. The script that is pulling the data will have to delete the files it has already processed and call "kill -HUP <pid>" to restart the copy.
Source directory should probably be relative (but not required). Destination does not have to be. Try it out on a smaller temporary tree.
You probably don't want to use this program as-is. It was writtin for a specific task of copying files and waiting for a signal.
You probably just want to use the listdir() method removing the desitination dir from the parameter list and also remove:
Hi crabboy. Thank you for your help. I modified the code as you have suggested. I then ran it using ./directory_2 /home/ee. This gives correct result, but when I used ./directory_2 /home or ./directory_2 /home/
it did not list any file but the stuff shown below continuously and then it resulted in a segmentation fault.
name = Flash
name = .
name = ..
name = Flash
name = .
name = ..
name = Flash
name = .
name = ..
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.