LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   A script that renames a folder to an integer after some other steps... (https://www.linuxquestions.org/questions/programming-9/a-script-that-renames-a-folder-to-an-integer-after-some-other-steps-582873/)

Cyberman 09-07-2007 03:38 AM

A script that renames a folder to an integer after some other steps...
 
I'm not too sure how to explain what I'm trying to do. I'll eventually open up some sed and awk books, but at the moment, I don't know how to do what I want.

prestart: mount /dev/something1

1. Rename */foldername/ to an integer stored in a file.
2. Pull integer from file.
3. If integer in file = 0, which is the default for just beginning, then rename folder to */1/
4. Store proof of integer change in file. Integer in file turns into 1.
5. Transfer files from */1/ to external medium
6. Delete */1/
7. umount /dev/something1

new start:

1. mount /dev/something1
2. Rename */foldername/ to an integer stored in the previously mentioned file
3. Since stored integer = 1, rename folder to */2/
4. Store proof of integer change in file. Integer in file turns into 2.
5. Transfer files from */2/ to external medium
6. Delete */2/
7. umount /dev/something1

You've got the idea, I guess.

*/foldername/ is never a number. It uses letters.
The integer goes up +1 each time.

wjevans_7d1@yahoo.co 09-07-2007 05:23 AM

You've explained it quite well!

We won't do the work for you, of course, but here's a good place to raise any specific questions.

My question for you is:

What does your script look like so far?

Cyberman 09-08-2007 01:15 AM

Quote:

Originally Posted by wjevans_7d1@yahoo.co (Post 2884209)
You've explained it quite well!

We won't do the work for you, of course, but here's a good place to raise any specific questions.

My question for you is:

What does your script look like so far?

Looks like the below. I researched awk and sed. I'm lost as how to do the "quoted" part with sed.

#!/bin/sh
#
# Filename: super-transfer.sh
#
# ===========================
# mount devices
# ===========================
#
#
mkdir /mnt/abc1/
mkdir /mnt/xyz/
mount /dev/abc1 /mnt/abc1/
mount /dev/xyz /mnt/xyz/
#
# ======================================
# Pull, examine, and create new integer
# * Scripts are located in home directory
# ======================================
# * folder-renaming.x naturally contains a 0; it was a manually created file.
#
awk '{ print expr $1 + 1 > "folder-renaming.x"}' folder-renaming.x
#
#
# ======================================
# Change variable of saving folder
# ======================================
#
#
# I don't have full understanding of sed.
# I was playing with sed, but I can't figure out how to
# assign a variable to something part of the folder-directory system
# Example: /information/$variable/
# I figure I would do something like this:
#
#-----------------------------------------------------------
sed '/$variable/s//$1/g' # I know this isn't right at all
#-----------------------------------------------------------
#
#
# $1 would be from folder-renaming.x
# and $variable would be from the script that saves stuff
#
#________________________________________________________________
Quote:

# This would be that script: (not part of super-transfer.sh)
# Let's call this next, outside script "copystuff.sh"
#________________________________________________________________
#===============================================
##!/bin/sh
##copy stuff to storage medium
#-------------------------------------------------
# mkdir /mnt/abc1/information
# mkdir /mnt/abc1/information/$variable/
# cp /mnt/xyz/folder/ /mnt/abc1/information/$variable/
#-------------------------------------------------
#===============================================
#
# I want $variable to be replaced with the new variable
# that was created inside of folder-renaming.x
# I suppose I would have to use sed, but I wouldn't know how.
# I don't know how to make it handle two files; I only know how to
# make it handle the editing and replacing of one file at the moment.
exit 0
#
#________________________________________________________________
#________________________________________________________________
#________________________________________________________________
#
# We are now looking at super-transfer.sh again
#
#
# ===========================
# delete folder
# ===========================
#
rmdir /mnt/xyz/folder/
#
#
# ===========================
# unmount devices
# ===========================
#
#
umount /dev/abc1 /mnt/abc1/
umount /dev/xyz /mnt/xyz/
#
#
#
exit 0

wjevans_7d1@yahoo.co 09-08-2007 11:43 AM

Quoth Cyberman:
Code:

sed '/$variable/s//$1/g' # I know this isn't right at all
So put that line (or something like it) in a tiny script of its own, along with the minimum of other stuff to give that line what it needs (such as setting any variables).

Then run the script, feeding it data by hand and watching it not work.

Come back here with the tiny script, what you fed it, what you got as output, and what you wanted.

That work for you? (grin)

Cyberman 09-08-2007 12:58 PM

You're not very helpful. You might as well not respond. (^)--o
My finger goes out to you for acting like Socrates.
You could have at least given a weblink, but I figure you're just trying to bring your posts number up.

Screw it. I'll buy the code. I have more money than time for this b.s.

wjevans_7d1@yahoo.co 09-11-2007 07:32 AM

If you have more money than time, I can understand.

At seemingly regular intervals, I answer requests for solutions to problems by leading the original poster to solve such problems on his own.

It's regrettable that this approach is not the best one for you, but if you can "buy the code", at least your problem is solved.

Best wishes.


All times are GMT -5. The time now is 08:25 PM.