LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-07-2007, 03:38 AM   #1
Cyberman
Member
 
Registered: Aug 2005
Distribution: Debian Stable
Posts: 218

Rep: Reputation: 17
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.

Last edited by Cyberman; 09-07-2007 at 03:40 AM.
 
Old 09-07-2007, 05:23 AM   #2
wjevans_7d1@yahoo.co
Member
 
Registered: Jun 2006
Location: Mariposa
Distribution: Slackware 9.1
Posts: 938

Rep: Reputation: 31
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?
 
Old 09-08-2007, 01:15 AM   #3
Cyberman
Member
 
Registered: Aug 2005
Distribution: Debian Stable
Posts: 218

Original Poster
Rep: Reputation: 17
Quote:
Originally Posted by wjevans_7d1@yahoo.co View Post
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

Last edited by Cyberman; 09-08-2007 at 01:38 AM.
 
Old 09-08-2007, 11:43 AM   #4
wjevans_7d1@yahoo.co
Member
 
Registered: Jun 2006
Location: Mariposa
Distribution: Slackware 9.1
Posts: 938

Rep: Reputation: 31
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)
 
Old 09-08-2007, 12:58 PM   #5
Cyberman
Member
 
Registered: Aug 2005
Distribution: Debian Stable
Posts: 218

Original Poster
Rep: Reputation: 17
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.

Last edited by Cyberman; 09-08-2007 at 01:15 PM.
 
Old 09-11-2007, 07:32 AM   #6
wjevans_7d1@yahoo.co
Member
 
Registered: Jun 2006
Location: Mariposa
Distribution: Slackware 9.1
Posts: 938

Rep: Reputation: 31
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.
 
  


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
converting string in integer in bash script dziadgba Linux - Newbie 5 08-31-2009 05:59 PM
Samba File Server Renames Directories bgearig Linux - Server 3 10-24-2007 10:53 AM
Need a Download Mgr that renames duplicate filenames RyMcV Linux - Software 1 07-01-2007 03:51 PM
noob needs help with: wireless device renames itself on reboot... odd... mfinkel Linux - Hardware 0 04-10-2006 05:33 PM
Shell-Script check if $xx is of type integer d-fens Programming 5 07-11-2003 08:38 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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