LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Networking (https://www.linuxquestions.org/questions/linux-networking-3/)
-   -   Automate Samba logon with a bash script? (https://www.linuxquestions.org/questions/linux-networking-3/automate-samba-logon-with-a-bash-script-483195/)

achtung_linux 09-13-2006 02:30 PM

Automate Samba logon with a bash script?
 
Hi,
I am trying to write a script that will fetch a file from a Windows machine and execute it on Linux. Since I am using Samba for all the Linux-Windows file traffic, I am always confronted with the "password: " prompt when trying to script my way in the Windows shared folders. How to script the login part of Samba so that file fetching is automated?
P.S. Maybe this topic is not networking per se, maybe more like "Linux programming" so I apologize to moderators for possible abuse...

achtung_linux 09-13-2006 05:22 PM

OK, I've got out of the "password: " loop by using the -n handle, that way Samba isn't asking for password. But now all it does is just... sitting there accepting no commands.
How to get the script to keep on passing commands to Samba once the connection is open

changlinn 10-16-2006 09:07 AM

I have spent the last couple of days looking for a solution to this as well, can you pot what you have already and I will try and help, at the moment, I am testing .bashrc and crontab to trying and get this working.

andrewdodsworth 10-18-2006 04:26 PM

I create a directory on the linux box called /Win_remote and I can then mount the windows share:

/bin/mount -t smbfs -o username=<win_user>,password=<win_passwd> //<Win_machine_name>/<sharename> /Win_remote/

Once you've done that you can do anything on any file in the /Win_remote directory. I use it for backing up Windows machines to the server.

changlinn 10-20-2006 04:13 PM

Problem is I think the op and me are actually using Linux workstations.
I have done a lot more research since I posted here, and it is simply not possible to script stuff to work on login that allows for mapping of drives (like windows).
Your best bet, and something I am looking at at the moment, is a multitude of scripts.
My linux pc's that I am testing all this on is a member of the windows domain. So I have a static mount specified to /mnt/linux this is where all my scripts, login, boot, cron-hourly and cron-daily are stored. Various scripts call these. A good one is a method of doing a boot script using a script generator that runs the boot script on the server, script generator here: http://rob.pectol.com/content/view/17/33/ this script is only called once at boot, but you can do things like making sure their /etc/cups/printers.conf is right, this script has full rights.
The next one is the login script, called by ~/.gnomerc which is just simply a file that runs scripts after login, but as the user logging in, so you can't mount drives this way, unless you 755 mount which I guess you could do, but the problem then is mount has no way of grabbing the users current username and password that I am aware of.
The next ones are just hourly and daily scripts to script things like updates, virus scans etc.
The one I am currently looking into, and am hopeful I can get working is pam-mount that can mount shares (can even create the mount points if not available) so eg it takes & as the usersname you can have in your pam-mount.conf hasn't worked so far, but hopefully I can get there.
I'll let you know how I go, I am also writing a guide that I'll put online.

achtung_linux 10-21-2006 12:02 PM

Have anyone had any expirience with Expect? Or maybe tried to solve this kind of problem with Expect and has any expiriences to share?
P.S. Expect is a program that uses Tcl plus its own syntax to script the login and pass commands from a script as if a real user has logged in...

changlinn 10-22-2006 02:36 AM

well got pam-mount working. Very pleased with myself.

Found the below info nowhere else, even on guides to do with pam-mount, found it in some obscure debian guide. This is what made it work.

add this to the end of /etc/pam.d/common-auth
auth optional pam_mount.so use_first_pass

add this to the end of /etc/pam.d/common-session
session optional pam_mount.so

No to figure out if domain logins can be cached so that laptops can be members of the domain but work away from the domain. I don't think they can. The other thing I need to work out is if I can get the Linux workstations to query either Domain controller incase one goes down.


All times are GMT -5. The time now is 01:54 PM.