Link to home
Start Free TrialLog in
Avatar of Rosa2003
Rosa2003

asked on

Running a shell script with Samba commands

Can I run a shell script on Linux RedHat 9 and then run samba commands?

Is it possible to have a shell script to run all this commands:


# smbclient //MyWindowsServer/MySharedCarpet -U administrator
Password:***

smb: \> prompt  
smb: \> recurse
smb: \> lcd /home
smb: \> mput *.*
smb: \> lcd /var/spool/mail
smb: \> mput *.*
smb: \> exit
ASKER CERTIFIED SOLUTION
Avatar of blkline
blkline

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of blkline
blkline

BTW, here's an article that describes the process:

http://www.mcpressonline.com/mc?50@119.TIfbctTRalJ.1@.6ae5da73

While I've never used expect (I'm sure it's great) an easy way to accomplish this is with echo.

Try:

echo -ne "prompt\nrecurse\nlcd /home\nmput *.*\nlcd /var/spool/mail\nmput *.*\nexit

You should get a list of commands, separated by newlines:
prompt
recurse
lcd /home
etc...

Next, pipe (|) these to your smbclient command:

echo -ne "prompt\nrecurse\nlcd /home\nmput *.*\nlcd /var/spool/mail\nmput *.*\nexit | smbclient //MyWindowsServer/MySharedCarpet -U administrator
Password:***
Avatar of Rosa2003

ASKER

Just to share knowledge, I wrote an expect script to copy files from Linux to Windows using Samba. It works fine:

#!/usr/bin/expect -f
#
# This Expect script was generated by autoexpect on
Thu Sep 30 19:07:58 2004
# Expect and autoexpect were both written by Don
Libes, NIST.
#
# Note that autoexpect does not guarantee a working
script.  It
# necessarily has to guess about certain things.

set force_conservative 0  ;# set to 1 to force
conservative mode even if
                    ;# script wasn't run conservatively originally
if {$force_conservative} {
      set send_slow {1 .1}
      proc send {ignore arg} {
            sleep .1
            exp_send -s -- $arg
      }
}

set timeout -1
spawn smbclient //MyWindowsServer/mailsbackup -U
administrador
match_max 100000
expect -exact "added interface ip=192.168.1.50
bcast=192.168.1.255 nmask=255.255.255.0\r
added interface ip=192.168.0.1 bcast=192.168.0.255
nmask=255.255.255.0\r
Got a positive name query response from 192.168.1.13 (
192.168.1.13 )\r
Password: "
send -- "MyWindowsServer\r"
expect -exact "\r
Domain=\[WORKGROUP\] OS=\[Windows Server 2003 3790\]
Server=\[Windows Server 2003 5.2\]\r
\r\rsmb: \\> \rsmb: \\> "
send -- "prompt"
send -- "\r"
send -- "recurse"
send -- "\r"
send -- "cd /inbox"
send -- "\r"
send -- "lcd /var/spool/mail"
send -- "\r"
send -- "mput *.*"
send -- "\r"
send -- "exit"
send -- "\r"
expect -exact "\rsmb: \\> exit\rsmb: \\> exit"