+ Post New Thread
Results 1 to 12 of 12
*nix Thread, Copy file across variable folder name in Technical; I had to make sure 20 original eeePC 701s to allow access to an intranet page on local server and ...
  1. #1

    SimpleSi's Avatar
    Join Date
    Jun 2005
    Location
    Lancashire
    Posts
    5,829
    Thank Post
    1,476
    Thanked 594 Times in 446 Posts
    Rep Power
    169

    Copy file across variable folder name

    I had to make sure 20 original eeePC 701s to allow access to an intranet page on local server and so I had to go into Firefox settings and set it to bypass using the RBC proxy server for local addresses and set a consistant default homepage.

    After doing a few, I worked out it was easier to copy prefs.js from one machine to a network folder and then copy it onto each of the other machines using the File Manager.

    I wanted to knock up a script nut the problem I have is that the folder name keeps changing from machine to machine.

    the prefs.js file is held in something like (not got a machine handy now) ...

    /user/.mozilla/firefox/variablefoldername/prefs.js

    Is there a way of writing a script that can handle the variable foldername and just copy the prefs.js file from

    /home/classwork/technical/prefs.js which is an SMB mounted share on the server.

    regards

    Simon

  2. #2
    ChrisH's Avatar
    Join Date
    Jun 2005
    Location
    East Lancs
    Posts
    4,993
    Thank Post
    120
    Thanked 286 Times in 263 Posts
    Rep Power
    108
    It should start something like

    Code:
    locate prefs.js|grep ^"\/home"
    I am just trying to figure out the rest of the regular expression to include firefox and prefs.jf.

  3. #3

    Ric_'s Avatar
    Join Date
    Jun 2005
    Location
    London
    Posts
    7,592
    Thank Post
    109
    Thanked 770 Times in 598 Posts
    Rep Power
    183
    For a start, you might find this handy... Advanced Bash-Scripting Guide

    I'm a bit lazy so cannot be bothered testing this

    Code:
    #!/bin/bash
    
    prefsLocation='locate prefs.js | grep ^"\/home"'
    
    cp /home/classwork/technical/prefs.js $prefsLocation
    P.S. You may need to force the filecopy (if the file is read only)

  4. #4
    ChrisH's Avatar
    Join Date
    Jun 2005
    Location
    East Lancs
    Posts
    4,993
    Thank Post
    120
    Thanked 286 Times in 263 Posts
    Rep Power
    108
    Code:
    locate prefs.js|grep ^/home/.*/firefox/.*prefs.js$
    This should be a little more robust in the case on my system there is other other prefs.jf from other mozilla products like thunderbird.
    Last edited by ChrisH; 9th March 2009 at 09:09 PM.

  5. Thanks to ChrisH from:

    SimpleSi (9th March 2009)

  6. #5

    Ric_'s Avatar
    Join Date
    Jun 2005
    Location
    London
    Posts
    7,592
    Thank Post
    109
    Thanked 770 Times in 598 Posts
    Rep Power
    183
    Quote Originally Posted by ChrisH View Post
    Code:
    locate prefs.js|grep ^/home/.*/firefox/.*prefs.js$
    This should be a little more robust in the case on my system there is other other prefs.jf from other mozilla products like thunderbird.
    The following might be better, just incase you've set up more than one user on your netbooks.

    Code:
    locate prefs.js|grep ^/home/user/.*/firefox/.*prefs.js$
    You could also set conditions for it to drop out gracefully if the prefs file isn't found, etc. It depends whether you want something to quickly do the job or something to be more robust for future use.

    Oh yeah... the script above also assumes that the SMB share is already mounted.

  7. Thanks to Ric_ from:

    SimpleSi (9th March 2009)

  8. #6

    SimpleSi's Avatar
    Join Date
    Jun 2005
    Location
    Lancashire
    Posts
    5,829
    Thank Post
    1,476
    Thanked 594 Times in 446 Posts
    Rep Power
    169
    I'll have to try these out tmrrw when I'm back there and see what they do
    regards

    Simon

  9. #7
    ChrisH's Avatar
    Join Date
    Jun 2005
    Location
    East Lancs
    Posts
    4,993
    Thank Post
    120
    Thanked 286 Times in 263 Posts
    Rep Power
    108
    hmmm I see what your getting at now
    Last edited by ChrisH; 9th March 2009 at 11:25 PM.

  10. #8

    SimpleSi's Avatar
    Join Date
    Jun 2005
    Location
    Lancashire
    Posts
    5,829
    Thank Post
    1,476
    Thanked 594 Times in 446 Posts
    Rep Power
    169
    I'm getting
    Code:
    locate: /var/cache/locate/locatedb: No such file or directory


    Even if I try
    Code:
    locate t1.url
    and t1.url is in the /home/user directory and I'm in the same directory it gives ther same error msg

    regards

    Simon

  11. #9

    SimpleSi's Avatar
    Join Date
    Jun 2005
    Location
    Lancashire
    Posts
    5,829
    Thank Post
    1,476
    Thanked 594 Times in 446 Posts
    Rep Power
    169
    The find command does the job instead though :
    Code:
    #!/bin/bash
    
    prefslocation=$(find /home/user/.mozilla/firefox -name prefs.js)
    
    cp /home/user/classwork/technical/prefs.js $prefslocation


    regards
    Simon

  12. #10
    ChrisH's Avatar
    Join Date
    Jun 2005
    Location
    East Lancs
    Posts
    4,993
    Thank Post
    120
    Thanked 286 Times in 263 Posts
    Rep Power
    108
    You might need to issue the command

    Code:
    updatedb
    to get it working initially but since you got it working with find

  13. #11

    Ric_'s Avatar
    Join Date
    Jun 2005
    Location
    London
    Posts
    7,592
    Thank Post
    109
    Thanked 770 Times in 598 Posts
    Rep Power
    183
    I meant to update this to use find anyway because the locate command doesn't come with all distros (thus this script isn't that useful in other situations).

  14. #12

    SimpleSi's Avatar
    Join Date
    Jun 2005
    Location
    Lancashire
    Posts
    5,829
    Thank Post
    1,476
    Thanked 594 Times in 446 Posts
    Rep Power
    169
    Thanks for showing the way

    One thing I learnt was that you can't put spaces around the = e.g
    Code:
    prefslocation = $(....)
    gives an error

    Not a clever feature

    regards

    Simon

SHARE:
+ Post New Thread

Similar Threads

  1. Replies: 5
    Last Post: 29th January 2013, 10:16 AM
  2. vbscript to copy a folder & delete a folder
    By MicrodigitUK in forum Scripts
    Replies: 2
    Last Post: 29th January 2009, 12:43 PM
  3. how to copy folder using putty
    By ranj in forum *nix
    Replies: 2
    Last Post: 26th June 2008, 05:46 PM
  4. Batch: Text file -> Environment variable?
    By PiqueABoo in forum Scripts
    Replies: 5
    Last Post: 13th December 2006, 11:09 PM
  5. Replies: 4
    Last Post: 23rd March 2006, 06:27 AM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •