Solved

Running a shell script with Samba commands

Posted on 2004-09-30
4
3,608 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
  • 2
4 Comments
 
LVL 6

Accepted Solution

by:
blkline earned 300 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Introduction We as admins face situation where we need to redirect websites to another. This may be required as a part of an upgrade keeping the old URL but website should be served from new URL. This document would brief you on different ways ca…
Linux users are sometimes dumbfounded by the severe lack of documentation on a topic. Sometimes, the documentation is copious, but other times, you end up with some obscure "it varies depending on your distribution" over and over when searching for …
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

762 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now