Solved

Running a shell script with Samba commands

Posted on 2004-09-30
4
3,626 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
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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

This is the error message I got (CODE) Error caused by incompatible libmp3lame 3.98-2 with ffmpeg I've googled this error message and found out sometimes it attaches this note "can be treated with downgrade libmp3lame to version 3.97 or 3.98" …
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

910 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

20 Experts available now in Live!

Get 1:1 Help Now