?
Solved

Running a shell script with Samba commands

Posted on 2004-09-30
4
Medium Priority
?
3,790 Views
Last Modified: 2013-12-16
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
Comment
Question by:Rosa2003
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 6

Accepted Solution

by:
blkline earned 600 total points
ID: 12193011
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
 
LVL 6

Expert Comment

by:blkline
ID: 12193034
BTW, here's an article that describes the process:

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

0
 
LVL 2

Expert Comment

by:blentz
ID: 12212508
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
 
LVL 1

Author Comment

by:Rosa2003
ID: 12241089
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Little introduction about CP: CP is a command on linux that use to copy files and folder from one location to another location. Example usage of CP as follow: cp /myfoder /pathto/destination/folder/ cp abc.tar.gz /pathto/destination/folder/ab…
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Suggested Courses
Course of the Month12 days, 11 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question