Replace part of folder(s)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Replace part of folder(s)
# 22  
Old 05-04-2013
Quote:
When called from shell script file:
The desired output ASWELL as the
unwanted *.deb.x folders are there.
There is likely another detail being missed. Smilie It should work fine from a shell script. You would need to post what happened. Here's what I see, it works here:
Code:
$ pwd
/tmp

Code:
$ cat test.sh
# Remove .deb.x extension from any directory name
# DIR=/var/mobile/Media/Downloads
DIR=/tmp/xxx
echo Before:
file $DIR/*
for old_sub in $DIR/*.deb.x; do
  if [ -d "$old_sub" ]; then
    new_sub=$(echo "$old_sub" | sed "s/\.deb\.x$//")
    mv "$old_sub" "$new_sub"
  fi
done
echo After:
file $DIR/*

Code:
$ cat test2.sh
echo Entering test2.sh
/tmp/test.sh
echo Leaving test2.sh

Code:
$ ./test2.sh
Entering test2.sh
Before:
/tmp/xxx/dir.deb.x:  directory
/tmp/xxx/file.deb.x: ASCII text
After:
/tmp/xxx/dir:        directory
/tmp/xxx/file.deb.x: ASCII text
Leaving test2.sh

# 23  
Old 05-04-2013
hmm... calling from script: (actually run.sh calls another shell called "xtractall.sh" and that is the script being executed... if that matters)
Code:
login as: root
root@192.168.1.74's password:
Pascals-iPhone:~ root# exec run.sh
Before:
/var/mobile/Media/Downloads/Ac.deb:            Debian binary package (format 2.0)
/var/mobile/Media/Downloads/Ac.deb.x:          directory
/var/mobile/Media/Downloads/Brc.deb:           Debian binary package (format 2.0)
/var/mobile/Media/Downloads/Brc.deb.x:         directory
/var/mobile/Media/Downloads/CleanUP.deb:       Debian binary package (format 2.0)
/var/mobile/Media/Downloads/CleanUP.deb.x:     directory
After:
/var/mobile/Media/Downloads/Ac:                directory
/var/mobile/Media/Downloads/Ac.deb:            Debian binary package (format 2.0)
/var/mobile/Media/Downloads/Brc:               directory
/var/mobile/Media/Downloads/Brc.deb:           Debian binary package (format 2.0)
/var/mobile/Media/Downloads/CleanUP:           directory
/var/mobile/Media/Downloads/CleanUP.deb:       Debian binary package (format 2.0)
Pascals-iPhone:~ root# cd /var/mobile/Media/Downloads
Pascals-iPhone:/var/mobile/Media/Downloads root# ls
Ac/      Ac.deb.x/  Brc.deb*    CleanUP/      CleanUP.deb.x/
Ac.deb*  Brc/       Brc.deb.x/  CleanUP.deb*
Pascals-iPhone:/var/mobile/Media/Downloads root#

directly:
Code:
Pascals-iPhone:~ root# exec xtractall.sh
Before:
/var/mobile/Media/Downloads/Ac:                directory
/var/mobile/Media/Downloads/Ac.deb:            Debian binary package (format 2.0)
/var/mobile/Media/Downloads/Ac.deb.x:          directory
/var/mobile/Media/Downloads/Brc:               directory
/var/mobile/Media/Downloads/Brc.deb:           Debian binary package (format 2.0)
/var/mobile/Media/Downloads/Brc.deb.x:         directory
/var/mobile/Media/Downloads/CleanUP:           directory
/var/mobile/Media/Downloads/CleanUP.deb:       Debian binary package (format 2.0)
/var/mobile/Media/Downloads/CleanUP.deb.x:     directory
After:
/var/mobile/Media/Downloads/Ac:                directory
/var/mobile/Media/Downloads/Ac.deb:            Debian binary package (format 2.0)
/var/mobile/Media/Downloads/Brc:               directory
/var/mobile/Media/Downloads/Brc.deb:           Debian binary package (format 2.0)
/var/mobile/Media/Downloads/CleanUP:           directory
/var/mobile/Media/Downloads/CleanUP.deb:       Debian binary package (format 2.0)
Pascals-iPhone:~ root# cd /var/mobile/Media/Downloads
Pascals-iPhone:/var/mobile/Media/Downloads root# ls
Ac/  Ac.deb*  Brc/  Brc.deb*  CleanUP/  CleanUP.deb*
Pascals-iPhone:/var/mobile/Media/Downloads root#


Last edited by pasc; 05-04-2013 at 04:28 PM..
# 24  
Old 05-04-2013
Code:
exec xtractall.sh

Is there some requirement to use exec on the iphone OS? What if you tried leaving that off? Normally, exec is rarely or never required.
---------------------------
Code:
After:
/var/mobile/Media/Downloads/Ac:                directory
/var/mobile/Media/Downloads/Ac.deb:            Debian binary package (format 2.0)
/var/mobile/Media/Downloads/Brc:               directory
/var/mobile/Media/Downloads/Brc.deb:           Debian binary package (format 2.0)
/var/mobile/Media/Downloads/CleanUP:           directory
/var/mobile/Media/Downloads/CleanUP.deb:       Debian binary package (format 2.0)
Pascals-iPhone:~ root# cd /var/mobile/Media/Downloads
Pascals-iPhone:/var/mobile/Media/Downloads root# ls
Ac/      Ac.deb.x/  Brc.deb*    CleanUP/      CleanUP.deb.x/
Ac.deb*  Brc/       Brc.deb.x/  CleanUP.deb*

Doesn't make sense. "After:" (from file *) shows six files / dirs. The ls shows nine. Doesn't add up. Try doing ls -l to help figure out what the difference is, why three .x dirs supposedly show up in one listing, not the other.

----------------------
Code:
Before:
/var/mobile/Media/Downloads/Ac:                directory
/var/mobile/Media/Downloads/Ac.deb:            Debian binary package (format 2.0)
/var/mobile/Media/Downloads/Ac.deb.x:          directory
/var/mobile/Media/Downloads/Brc:               directory
/var/mobile/Media/Downloads/Brc.deb:           Debian binary package (format 2.0)
/var/mobile/Media/Downloads/Brc.deb.x:         directory
/var/mobile/Media/Downloads/CleanUP:           directory
/var/mobile/Media/Downloads/CleanUP.deb:       Debian binary package (format 2.0)
/var/mobile/Media/Downloads/CleanUP.deb.x:     directory

---------------------------------------------------

If the Before: situation already has both Ac and Ac.deb.x directories, then when mv Ac.deb.x Ac runs, it does not rename Ac.deb.x to Ac, but instead moves Ac.deb.x to be a subdirectory of the existing Ac directory. The script assumes that the renamed directories do not already exist.
Code:
$ file *
dir:        directory
dir.deb.x:  directory
file.deb.x: ASCII text
$ ls dir
$ mv dir.deb.x dir
$ file *
dir:        directory
file.deb.x: ASCII text
$ ls dir
dir.deb.x

Taking into account that the final directory may already exist, and adding an ls -ld at the end:
Code:
# Remove .deb.x extension from any directory name
# DIR=/var/mobile/Media/Downloads
DIR=/tmp/xxx
echo Before:
file $DIR/*
for old_sub in $DIR/*.deb.x; do
  if [ -d "$old_sub" ]; then
    new_sub=$(echo "$old_sub" | sed "s/\.deb\.x$//")
    if [ -d "$new_sub" ]; then
      echo "$new_sub" already exists
      # take action, such as: rmdir "$new_sub"
      # take action, such as: rm -r "$new_sub"
      # take action, such as: exit
    fi
    mv "$old_sub" "$new_sub"
  fi
done
echo After:
file $DIR/*
ls -ld $DIR/*

# 25  
Old 05-04-2013
Ok... this definitly falls into the category "weird"

Code:
login as: root
root@192.168.1.74's password:
Pascals-iPhone:~ root# cd /Applications/Debiant.app/
Pascals-iPhone:/Applications/Debiant.app root# ls
Default.png*   deinstall_disk.sh*     icon.png*   run.sh*
Info.plist*    deinstall_package.sh*  others/     xtractall.sh*
deinstall.sh*  extract.sh*            repack.sh*  yextractone.sh*
Pascals-iPhone:/Applications/Debiant.app root# ./run.sh
./run.sh: line 5:  9826 Illegal instruction: 4  sshpass -f /var/mobile/password.txt
mv: cannot stat `/var/mobile/*.deb': No such file or directory
Before:
/var/mobile/Media/Downloads/Ac.deb:        Debian binary package (format 2.0)
/var/mobile/Media/Downloads/Ac.deb.x:      directory
/var/mobile/Media/Downloads/Brc.deb:       Debian binary package (format 2.0)
/var/mobile/Media/Downloads/Brc.deb.x:     directory
/var/mobile/Media/Downloads/CleanUP.deb:   Debian binary package (format 2.0)
/var/mobile/Media/Downloads/CleanUP.deb.x: directory
After:
/var/mobile/Media/Downloads/Ac:          directory
/var/mobile/Media/Downloads/Ac.deb:      Debian binary package (format 2.0)
/var/mobile/Media/Downloads/Brc:         directory
/var/mobile/Media/Downloads/Brc.deb:     Debian binary package (format 2.0)
/var/mobile/Media/Downloads/CleanUP:     directory
/var/mobile/Media/Downloads/CleanUP.deb: Debian binary package (format 2.0)
drwxr-xr-x 4 root   mobile   136 May  5 01:21 /var/mobile/Media/Downloads/Ac
-rwxrwxrwx 1 mobile mobile 14924 Oct 16  2011 /var/mobile/Media/Downloads/Ac.deb
drwxr-xr-x 4 mobile staff    136 May  5 01:21 /var/mobile/Media/Downloads/Brc
-rwxrwxrwx 1 mobile mobile  5582 Jan 15  2012 /var/mobile/Media/Downloads/Brc.deb
drwxr-xr-x 4 mobile mobile   136 May  5 01:21 /var/mobile/Media/Downloads/CleanUP
-rwxrwxrwx 1 mobile mobile 64264 Oct 20  2012 /var/mobile/Media/Downloads/CleanUP.deb

Looks good so far, right ?

After I do this and then execute ls again, alakazam:
Code:
Pascals-iPhone:/Applications/Debiant.app root# cd /var/mobile/Media/Downloads

Pascals-iPhone:/var/mobile/Media/Downloads root# ls -l
total 88
drwxrwxrwx 5 mobile mobile   170 May  5 01:25 Ac/
-rwxrwxrwx 1 mobile mobile 14924 Oct 16  2011 Ac.deb*
drwxr-xr-x 4 root   mobile   136 May  5 01:25 Ac.deb.x/
drwxrwxrwx 5 mobile mobile   170 May  5 01:25 Brc/
-rwxrwxrwx 1 mobile mobile  5582 Jan 15  2012 Brc.deb*
drwxr-xr-x 4 mobile staff    136 May  5 01:25 Brc.deb.x/
drwxrwxrwx 5 mobile mobile   170 May  5 01:25 CleanUP/
-rwxrwxrwx 1 mobile mobile 64264 Oct 20  2012 CleanUP.deb*
drwxr-xr-x 4 mobile mobile   136 May  5 01:25 CleanUP.deb.x/
Pascals-iPhone:/var/mobile/Media/Downloads root#

I don't get it...
the .deb.x appear after the script finished.

btw: I executed with "./run.sh" this time maybe thats better than exec ?


I GOT AN IDEA !
Perhaps the .deb.x cannot be moved as long as their ownership is root:mobile ? The writing permission are set to 755 (opposed to the newly "correct" folders).
Maybe a "sudo chown mobile:mobile" and a "sudo chmod 777" should be incooperated into the script ?
=> That could explain why the script won't do the move complete and the commandline does, as it is being executed as root ?
I don't know what your script DOES TO THE FOLDERS exactly.... however after it resolves the premissions are messed up

I tried the following, create the folders with the deb.x extension, chmod / chown them to have 777 and mobile:mobile permissions/ownerships

THEN

I paused the script and checked the files with a fileviewer, => the permissions were correct !

AFTERWARDS

I let the script continue and checked right after it finished: same as usual: two folders and the deb.x ones have the messed up permission.
Weird however is that I always need to reload my folderview in order to see those folders.

Last edited by pasc; 05-04-2013 at 08:40 PM..
# 26  
Old 05-04-2013
Code:
./run.sh: line 5:  9826 Illegal instruction: 4  sshpass -f /var/mobile/password.txt
mv: cannot stat `/var/mobile/*.deb': No such file or directory

Do you know what these error messages are? You can't allow your script to have unresolved error messages.

------------------------------------

Quote:
I executed with "./run.sh" this time maybe thats better than exec ?
There is no point in using exec unless you have some special reason for using that command. So yes, just run the shell script.

------------------------------------

"After" ls -ld from script:
Code:
drwxr-xr-x 4 root   mobile   136 May  5 01:21 /var/mobile/Media/Downloads/Ac
-rwxrwxrwx 1 mobile mobile 14924 Oct 16  2011 /var/mobile/Media/Downloads/Ac.deb
drwxr-xr-x 4 mobile staff    136 May  5 01:21 /var/mobile/Media/Downloads/Brc
-rwxrwxrwx 1 mobile mobile  5582 Jan 15  2012 /var/mobile/Media/Downloads/Brc.deb
drwxr-xr-x 4 mobile mobile   136 May  5 01:21 /var/mobile/Media/Downloads/CleanUP
-rwxrwxrwx 1 mobile mobile 64264 Oct 20  2012 /var/mobile/Media/Downloads/CleanUP.deb

ls -l from command line:
Code:
drwxrwxrwx 5 mobile mobile   170 May  5 01:25 Ac/
-rwxrwxrwx 1 mobile mobile 14924 Oct 16  2011 Ac.deb*
drwxr-xr-x 4 root   mobile   136 May  5 01:25 Ac.deb.x/
drwxrwxrwx 5 mobile mobile   170 May  5 01:25 Brc/
-rwxrwxrwx 1 mobile mobile  5582 Jan 15  2012 Brc.deb*
drwxr-xr-x 4 mobile staff    136 May  5 01:25 Brc.deb.x/
drwxrwxrwx 5 mobile mobile   170 May  5 01:25 CleanUP/
-rwxrwxrwx 1 mobile mobile 64264 Oct 20  2012 CleanUP.deb*
drwxr-xr-x 4 mobile mobile   136 May  5 01:25 CleanUP.deb.x/

The *.deb files have the same file sizes and dates, but are a day old, so little hard to draw conclusion. It would be interesting to see exact date to verify really same files being examined, something like ls -l --time-style=full-iso if that works there.

But the Ac, Brc, and Cleanup directories have different timestamps, ownerships, and permissions (and # of links, after permissions), all of which are unexpected. For example, compare Ac directory in the two listings:
Code:
drwxr-xr-x 4 root   mobile   136 May  5 01:21 /var/mobile/Media/Downloads/Ac
drwxrwxrwx 5 mobile mobile   170 May  5 01:25 Ac/

You need to look around and figure out why the difference in the two listings. Two possibilities I can think of: 1) Some other process is changing the Ac directory after the script runs and before you examine it. 2) Somehow two parallel directories, the script is operating on one of the parallel directories, you are looking at the other one. Your posted code indicates you are in the same directory, but the different timestamp, owner and permissions suggests you are not.

-------------------------------

I don't know the policy about running root or some other user on the iphone. root should be able to do anything, but again there might be some difference on iphone. It would be best if whoever owns the files runs the script. I would think all the files would owned by mobile, and mobile would run the script.
# 27  
Old 05-05-2013
those aren't related.I even removed them by temporarily clearing the lines responsible:


Doesn't make a difference.


Like I said:
The ownership / permission change occurs right after the part of your script resolves.


Can you confirm this ?
# 28  
Old 05-05-2013
Quote:
The ownership / permission change occurs right after
the part of your script resolves. Can you confirm this ?
I cannot confirm that. Look at the Brc directory. Supposedly the group changes from "staff" to "mobile" after script runs. Why would that happen? What process would be changing the ownership and permissions on it's own? It is also possible there are two different directory structures that are somehow getting confused. You are dealing with a special device and situation.

You could try using the cd /var/mobile/Media/Downloads and ls -l commands at the end of the script, compare those results with what you see by hand.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to replace part of string?

Hi Gurus, I need to replace part of string in file, the string format is below: I can use ABCD to find string, then replace values after "=" sign ABCD_XXX=value ABCD_YYY=value after replace ABCD_XXX=new_value ABCD_YYY=new_value my OS is SunOS 5.10 Generic_150400-64 sun4v sparc sun4v ... (9 Replies)
Discussion started by: green_k
9 Replies

2. Red Hat

Identify the folder is part of which mount point

Dear, I am using Redhat 6.6 . How to identify a given directory is part of which mount point. (2 Replies)
Discussion started by: aneesha
2 Replies

3. Shell Programming and Scripting

awk to replace part of a column

dear all, I'm trying to use Awk to eliminate the last two characters from the first column in a file. This two characters are "-1" and I need to eliminate them from each row that I have in the files. The files have two columns and look like: ID_090-1 2 ID_3787-1 4 ID_0098-1 1 ID_12-1 4 I... (4 Replies)
Discussion started by: gabrysfe
4 Replies

4. Shell Programming and Scripting

SED - replace only on part of the string

Hello there, I need some help. I have a file containing this : $ cat file PARM1=(VAL11),PARM2=(VAL21,VAL22,VAL23),PARM3=(VAL31),PARM4=(VAL41,VAL42) and I need to replace all the ',' by '|' but only those which are between brackets. Output would be :... (10 Replies)
Discussion started by: Sephiburp
10 Replies

5. Shell Programming and Scripting

Replace a part of the string

Hi I need to Replace a part of string in between one complete string. For e.g.. in the file the value is as: jobnm_$code_xyz_001 In script we are having a variable code=$3, where $3=ab final output should be jobnm_ab_xyz_001. But it is not working. Your help will be... (1 Reply)
Discussion started by: vee_789
1 Replies

6. Shell Programming and Scripting

replace part of text of a line

Gurus, You know, I believe you do:-), the comnand uname -r give you the kernel version: serverA:~# uname -r 2.6.26-1-xen-amd64So, I want to replace this output inside in the line below that is inside the file: kernel = '/boot/vmlinuz-2.6.26-1-xen-amd64'Suppose, you move this file to ther... (2 Replies)
Discussion started by: iga3725
2 Replies

7. Shell Programming and Scripting

Suggestion to replace a part of script

I have the part of script: if ; then make_command="make -f $temp_file" print $make_command; err_file="${sym_objdir}error.log" $make_command 2>$err_file; cat $err_file; ] && ] && exit 1; exit 0 fi ... (5 Replies)
Discussion started by: Ajay_84
5 Replies

8. UNIX for Dummies Questions & Answers

regarding replace a part of a string

hi all. i have a file name like abcd_vbnh.a_p i have to copy it as abcd_vbnh.a every time... in unix not in perl please (7 Replies)
Discussion started by: madhu_aqua14
7 Replies

9. Shell Programming and Scripting

Find and replace a part of the word in Shell

I have a csv file in which there are numbers like 078976/9XXX 098754/8XXX I want to replace the XXX with null. I want to know the command/code to do this. I know how to replace the whole word/number. But don't know how to replace a part of it. Thanks in advance, Mihir (3 Replies)
Discussion started by: mihirk
3 Replies

10. Shell Programming and Scripting

using sed to replace a part of string

Hi, I have files that are named front1.txt to front999.txt. They are all in the same directory. To change "front" to "back", I am doing something like this. for file in *.txt; do new=`echo $file | sed 's/^**/back/g'` mv $file $new done My problem is what if files are named... (6 Replies)
Discussion started by: csejl
6 Replies
Login or Register to Ask a Question