Unix File Move Script

Good afternoon all,

I have a directory on my Unix box.  Everyhour I want to move the contents of this directory (1 file) and move it to a share on a windows box - presumably via a unc path.

My questions
1) Will the mv command work to a unc share on windows?
2) can anyone provide a snippet (or whole code) to allow me to do this?

I plan on running the script every hour via a cron job.

Many Thanks

K
techmissAsked:
Who is Participating?
 
arichakraConnect With a Mentor Commented:
Hi, Simply mount the Windows share in Linux/UNIX using following command & write a 2 line script to move file/folder..

mount -t cifs //Winserver/share -o username=Winusername,password=password /mnt
0
 
dougaugCommented:
You can do this using a unix ftp client but your windows box should have an active ftp server.
0
 
mlecceConnect With a Mentor Commented:
Hello,

The best way to to do this is to mount the share to a specific mount point on your system (i.e. /mnt/windowshare1/)

Your script should be as simple as the one attached.

Regards,
Moses
#!/bin/bash
mv /mydir/myfiles/* /mnt/windowshare1/

Open in new window

0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

 
Martin_J_ParkerCommented:
If you use Samba to mount the file system you could use mv
http://articles.techrepublic.com.com/5100-10878_11-5080709.html
0
 
techmissAuthor Commented:
Thanks I'm getting there.

Martin - with reference to that link do I actually put the mount command in the smb.conf file?

Cheers

K
0
 
TopguyzCommented:
smb.conf is for the Samba Server and is really only necessary if you want to share directories from Linux to Windows.

When mounting the shared windows directory you either put the mount command in one of your startup-scripts or you can put the necessary information in "/etc/fstab".
0
 
mlecceCommented:
You may wish to use the smbmount utility.  I have attached the help screen.
[root@linux]# smbmount
Usage: mount.smbfs service mountpoint [-o options,...]
Version 3.0.10-1.4E.12.2

Options:
      username=<arg>                  SMB username
      password=<arg>                  SMB password
      credentials=<filename>          file with username/password
      krb                             use kerberos (active directory)
      netbiosname=<arg>               source NetBIOS name
      uid=<arg>                       mount uid or username
      gid=<arg>                       mount gid or groupname
      port=<arg>                      remote SMB port number
      fmask=<arg>                     file umask
      dmask=<arg>                     directory umask
      debug=<arg>                     debug level
      ip=<arg>                        destination host or IP address
      workgroup=<arg>                 workgroup on destination
      sockopt=<arg>                   TCP socket options
      scope=<arg>                     NetBIOS scope
      iocharset=<arg>                 Linux charset (iso8859-1, utf8)
      codepage=<arg>                  server codepage (cp850)
      unicode                         use unicode when communicating with server
      lfs                             large file system support
      ttl=<arg>                       dircache time to live
      guest                           don't prompt for a password
      ro                              mount read-only
      rw                              mount read-write

This command is designed to be run from within /bin/mount by giving
the option '-t smbfs'. For example:
  mount -t smbfs -o username=tridge,password=foobar //fjall/test /data/test

Open in new window

0
 
techmissAuthor Commented:
I have use the command above but I get error 13 - permission denied, the share I am trying to connect to is not locked down to a level that should trigger this message.

After researching the problem on another Linux forum the concensus was that the domain had to be present in the command e.g.

mount -t cifs //Winserver/share -o username=domain/Winusername,password=password /mnt
but this won't work either as I am getting the help screen presumably because my syntax is incorrect.

Confused!

Thanks
K
0
 
simon3270Commented:
There needs to be a backslash rather than a slash between the domain and user.  In your example it would be:

  mount -t cifs //Winserver/share -o username=domain\\Winusername,password=password /mnt

You *can* type the above in manually, but it might be better in /etc/fstab, so that it happens automatically.  The trouble is that /etc/fstab is world-readable, so anyone can see your sensitive login information.  To avoid this, I would use a credentials file.  The manual mount line becomes:

  mount -t cifs //Winserver/share -o credentials=/etc/cred /mnt

or, in /etc/fstab

  //Winserver/share /mnt cifs credentials=/etc/cred 0 0

and /etc/cred contains:
  username=workdom\simon
  password=HelloMum

You can then assign tight permisions to /etc/cred so that only root can read it.

Simon

0
 
arichakraCommented:
Or you can create a normal local user at the Windows server itself & use it with mount -t cifs command.
0
 
techmissAuthor Commented:
Thanks for your replies, I will use the creds file when I have resloved the original problem (it's my first attempt)

I need to be sure I am using the correct syntax, as below

mount -t cifs //10.41.5.242/warehouse -o username=f1\\warehouse,password=P4$$w0rd /mnt

as I am getting error:

mount error 13 = Permission denied
Refer to the mount.cifs(8) manual page (e.g.man mount.cifs)

I have removed all the permissions to this share to a level that should not trigger this message (hence my asking if my command is 100%)

Cheers
K
0
 
simon3270Commented:
I see you have this in the Win95/98 Zone - if the windows box is indeed one of those, that might be the problem.  I have had great difficulty getting UNIX to mount from Win98 machines, and in getting Win98 machines to mount UNIX shares.  Do you have an XP or Vista machine that you could try this on?
0
 
techmissAuthor Commented:
Hi,

I have tried XP too and get the same message "Permission Denied"  I'm going to try it on a Wiin Server 2003 R2 box and see if that works.

Also - my kernel version is 2.6.9-42.ELsmp, does anyone know if this supports cifs?

Thanks

K
0
 
simon3270Commented:
That kernel certainly does support cifs - I've just mounted a Samba-shared disk on such a box (though I didn't have to enter a domain).

What is the output of "smbclient -L //10.41.5.242"
0
 
techmissAuthor Commented:
Output is:

[root@SVUKQAD1 /]# smbclient -L //10.41.5.242
params.c:Parameter() - Ignoring badly formed line in configuration file: create mask 777
params.c:Parameter() - Ignoring badly formed line in configuration file: create mask 777
params.c:Parameter() - Ignoring badly formed line in configuration file: create mask 777
params.c:Parameter() - Ignoring badly formed line in configuration file: create mask 777
params.c:Parameter() - Ignoring badly formed line in configuration file: create mask 777
params.c:Parameter() - Ignoring badly formed line in configuration file: create mask 777
params.c:Parameter() - Ignoring badly formed line in configuration file: create mask 777
params.c:Parameter() - Ignoring badly formed line in configuration file: create mask 777
params.c:Parameter() - Ignoring badly formed line in configuration file: create mask 777
Password:

What password does it require??

Cheers
K
0
 
techmissAuthor Commented:
Ah i've done it again with a blank password:

Anonymous login successful
Domain=[F1] OS=[Windows 5.1] Server=[Windows 2000 LAN Manager]

        Sharename       Type      Comment
        ---------       ----      -------
Error returning browse list: NT_STATUS_ACCESS_DENIED
session request to 10.41.5.242 failed (Called name not present)
session request to 10 failed (Called name not present)
Anonymous login successful
Domain=[F1] OS=[Windows 5.1] Server=[Windows 2000 LAN Manager]

        Server               Comment
        ---------            -------

        Workgroup            Master
        ---------            -------
0
 
techmissAuthor Commented:
The main problem with this was that my password had $$ in it, Linux did not like this, when I changed password to an easier one it connected.

Thanks for all your help.

K
0
 
techmissAuthor Commented:
Unrelated password complexity was (seems) to be the root cause so I have distributed points to experts who were most helpful.

Thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.