LinuxQuestions.org
Help answer threads with 0 replies.
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 11-05-2004, 03:58 AM   #1
satimis
Senior Member
 
Registered: Apr 2003
Posts: 3,428

Rep: Reputation: 53
How to automatically date the input directories


Hi folks,

How to automatically date the input directories

I have following script with preset directories which can be dated automatically when they are copied for burning

Script:-
Code:
#!/bin/bash
set -x

#Set directory path...
user=$(whoami)
now=$(date +%Y.%m.%d.%R)
ISO_File="/tmp/satimis/image_${user}_${now}.iso"

# Temporary file to store the resulting mkisofs command
CmdFile_1=/tmp/satimis/.TmpBurnCD$$
list=""

CopyDir(){
name=$1
dir=$2

if [ "$Default" = "" ];then
list="$list \"$name=$dir\""
else
if [ "$Default" = "yes" ];then
list="$list \"$name=$dir\""
fi
fi
}

# Preset directories for copying...
B123() {
CopyDir "/B123_${now}/" "/pathto/B123"
}

C123() {
CopyDir "/C123_${now}/" "/pathto/C123/"
}

D123() {
CopyDir "/D123_${now}/" "/pathto/D123/"

# Choosing preset directores for copying
REPLY="B"
until [ -z "$REPLY" ]

do
echo "Choose any of the following:"
echo
echo "[B]123"
echo "[C]123"
echo "[D]123"
echo "[A]ll
echo
echo "[Enter] = Exit"
echo

read

case "$REPLY" in

# Accept upper or lowercase input...
"B" | "b" )
B123
;;

"C" | "c" )
C123
;;

"D" | "d" )
D123
;;

"A" | "a" )
B123
C123
D123
;;

* )
#Default option.
# Do nothing for other keys
;;

esac
done

# Loop to get other directories...
echo "Enter directories to burn. Leave blank to end list"
entry="empty"

until [ -z $entry ]; do
echo -n "Enter a directory (eg: /ABC/=/pathto/ABC): "
read entry
if [ "$entry" != "" ]; then
list="$list \"$entry\""
fi
done

# If at least one directory has been entered....
if [ "$list" != "" ];then
#Construct the mkisofs command...
echo "/usr/bin/mkisofs -R -l -o $ISO_File -hide-rr-moved -graft-points \
$list" > "$CmdFile_1"
.......
.....
Now my problem is unable to automatically date additional directories input. I tried many variation on;

if [ "$entry" != "" ]; then
and

list="$list \"$entry\""
without result, such as;

"$entry" != "_${now}"
"$entry" "!_${now}"= ""
"$entry" != ""_${now}
list="$list \"$entry\_${now}\""
list="$list \"$entry${now}\""
etc.

Since the pattern of input is "/ABC/=/pathto/ABC" I'm not allowed to separate it.

Any advice. TIA

B.R.
satimis
 
Old 11-05-2004, 05:32 AM   #2
dustu76
Member
 
Registered: Sep 2004
Distribution: OpenSuSe
Posts: 153

Rep: Reputation: 30
Try this:

Code:
until [ -z $entry ]; do
echo -n "Enter a directory (eg: /ABC/=/pathto/ABC): "
read entry
if [ "$entry" != "" ]; then
  ### FOR DATE PADDING
  dt_path=$(echo $entry |awk -F"=" '{print $2}')
  point=$(echo $entry |awk -F"=" '{print $1}' |awk -F"/" '{print $2}')
  point=$(echo "/${point}_${now}/")
  entry=$(echo "/${point}/=${dt_path}"
list="$list \"$entry\""
fi
done
You can also use "cut" instead of "awk" but I think awk eliminates problems even if the user input for "entry" contains spaces.

HTH.
 
Old 11-05-2004, 05:36 AM   #3
dustu76
Member
 
Registered: Sep 2004
Distribution: OpenSuSe
Posts: 153

Rep: Reputation: 30
Replace,

Code:
entry=$(echo "/${point}/=${dt_path}"
With this:

Code:
entry=$(echo "/${point}/=${dt_path}")
Forgot the closing parenthesis.

HTH.
 
Old 11-05-2004, 06:50 AM   #4
satimis
Senior Member
 
Registered: Apr 2003
Posts: 3,428

Original Poster
Rep: Reputation: 53
Hi dustu76
Quote:
Try this:
Code:
until [ -z $entry ]; do
echo -n "Enter a directory (eg: /ABC/=/pathto/ABC): "
read entry
if [ "$entry" != "" ]; then
  ### FOR DATE PADDING
  dt_path=$(echo $entry |awk -F"=" '{print $2}')
  point=$(echo $entry |awk -F"=" '{print $1}' |awk -F"/" '{print $2}')
  point=$(echo "/${point}_${now}/")
  entry=$(echo "/${point}/=${dt_path}"
list="$list \"$entry\""
fi
done
You can also use "cut" instead of "awk" but I think awk eliminates problems even if the user input for "entry" contains spaces.
Tks for your advice on 2 postings which worked for me seamlessly. I never imagin so complicate.

Could your please help me to understand those lines.

TIA

B.R.
satimis
 
Old 11-05-2004, 07:50 AM   #5
dustu76
Member
 
Registered: Sep 2004
Distribution: OpenSuSe
Posts: 153

Rep: Reputation: 30
1. dt_path=$(echo $entry |awk -F"=" '{print $2}')
2. point=$(echo $entry |awk -F"=" '{print $1}' |awk -F"/" '{print $2}')
3. point=$(echo "/${point}_${now}/")
4. entry=$(echo "/${point}/=${dt_path}")

Suppose entry is "/ABC/=/pathto/ABC"

Here we split this value into two parts, append the date to the first part & put them back together.

1. Save "/pathto/ABC"
2. Extract "ABC" from "${entry}"
3. Append "_${now}" to "ABC"
4. Put the "ABC_${now}" & "/pathto/ABC" back together.

HTH.
 
Old 11-05-2004, 10:11 PM   #6
satimis
Senior Member
 
Registered: Apr 2003
Posts: 3,428

Original Poster
Rep: Reputation: 53
Hi dustu76,

Quote:
Suppose entry is "/ABC/=/pathto/ABC"

Here we split this value into two parts, append the date to the first part & put them back together.

1. Save "/pathto/ABC"
2. Extract "ABC" from "${entry}"
3. Append "_${now}" to "ABC"
4. Put the "ABC_${now}" & "/pathto/ABC" back together.
Tks for your explanation.

"awk" is a handy tool which is new to me. Google search brought me many links;

http://www.vectorsite.net/tsawk.html
An AWK Tutorial
http://packetstormsecurity.nl/progra...awk/node2.html
Awk examples
http://www-cs.canisius.edu/PL_TUTORI...K/awk.examples
Index of /PL_TUTORIALS/AWK
http://www-cs.canisius.edu/PL_TUTORIALS/AWK/
[2.0] Awk Syntax
http://www.vectorsite.net/tsawk2.html
Awk Tutorial
http://stud.wsi.edu.pl/~robert/awk/
etc.

Could you please recommend me an awk documentation to read. TIA

B.R.
satimis
 
  


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
Ctrl+Shift Unicode input gone, after installing Japanese Input Methodes polemon Linux - Newbie 1 09-20-2005 06:17 PM
Possible to relocate RPM package to multiple directories bytaking dir input fromuser chalasaniv Linux - Software 0 10-08-2004 06:52 AM
Sendmail: timeout waiting for input from local during Draining Input andrewstr Linux - Software 0 07-14-2004 02:43 PM
my mouse input is takes as keyboard input in BASH e1000 Slackware 5 12-08-2003 04:00 PM
lastlog date does not match system date? jcmj Linux - Networking 6 10-22-2002 01:09 PM


All times are GMT -5. The time now is 09:07 PM.

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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration