• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3901
  • Last Modified:

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
0
Rosa2003
Asked:
Rosa2003
  • 2
1 Solution
 
blklineCommented:
One of the nicest ways I have seen to do that is by using the "expect" utility.  It allows a question/answer session.  I use it to automate ftp sessions, which are darned near identical to what you are using.

If it's not already loaded you can find expect in the expect-**.rpm package.

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

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

0
 
blentzCommented:
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:***
0
 
Rosa2003Author Commented:
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"
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now