# FreeBSD script in win ssh clients in one line?



## Lobster (Jun 25, 2010)

Please, help!

I use plink.exe in windowsXP i wont it exec my script but this script asks a password and it does not work

befor i did

```
chmod +rx add1.sh
```

in file.bat i have

```
plink.exe -ssh 10.10.30.72 -l root -pw 1234 /usr/local/etc/add1.sh
pause
```

script 

```
#!/bin/sh
mount_msdosfs /dev/da0s1 /mnt/usb
geli attach -k /mnt/usb/ad4s3d.key /dev/ad4s3d
mount /dev/ad4s3d.eli /usr/data/hdd12
df -h
```







command geli attach asks for password but i dont see it in the window

in PUTTY ssh terminal my script works, but theres nou way by one click start putty with command Ð–"((((((


----------



## mix_room (Jun 25, 2010)

> 3.7.3.6 -m: read a remote command or script from a file
> 
> The -m option performs a similar function to the "Remote command" box in the SSH panel of the PuTTY configuration box (see section 4.17.1). However, the -m option expects to be given a file name, and it will read a command from that file. On most Unix systems, you can even put multiple lines in this file and execute more than one command in sequence, or a whole shell script.
> 
> This option is not available in the file transfer tools PSCP and PSFTP.


http://the.earth.li/~sgtatham/putty/0.53/htmldoc/Chapter3.html#3.7.1


In any case: 
1) you probably cannot ssh in as root unless you have enabled it 
2) your password is useless. 
3) certificate-based logins


----------



## Lobster (Jun 25, 2010)

I used putty but it dont work too


```
putty.exe root@10.10.30.72 -m 2.txt
```

this command 


```
geli attach -k /mnt/usb/ad4s3d.key /dev/ad4s3d
```
does not ask the password


```
Using username "root".
Using keyboard-interactive authentication.
Password:
geli: Cannot read passphrase: Inappropriate ioctl for device.
                                                             mount: /dev/ad4s3d.eli : No such file or directory
```

but if i type this commnad in putty (started from icon) it works!


----------



## SirDice (Jun 25, 2010)

You can't script something interactive. If you want to script things like that you will have to use something like lang/p5-Expect.


----------



## Lobster (Jun 25, 2010)

No easy way to do it?


----------



## SirDice (Jun 25, 2010)

Lobster said:
			
		

> No easy way to do it?



Yes, with expect.


----------



## kisscool-fr (Jun 25, 2010)

You can try this in your add1.sh script


```
#!/bin/sh
mount_msdosfs /dev/da0s1 /mnt/usb
echo yourpasswd | geli attach -k /mnt/usb/ad4s3d.key /dev/ad4s3d
mount /dev/ad4s3d.eli /usr/data/hdd12
df -h
```

But it is not secure :\


----------



## Lobster (Jun 25, 2010)

SirDice said:
			
		

> Yes, with expect.



Its some sort of a language?!... hmmm not easy for me :e I cant finde manual with examples for it :stud only some articles form 1991 to 1997 !!!




			
				kisscool-fr said:
			
		

> But it is not secure :\



Yes


----------



## SirDice (Jun 25, 2010)

Lobster said:
			
		

> Its some sort of a language?!... hmmm not easy for me :e I cant finde manual with examples for it :stud only some articles form 1991 to 1997 !!!


It's quite old. 

http://en.wikipedia.org/wiki/Expect


----------



## kisscool-fr (Jun 25, 2010)

Lobster said:
			
		

> Yes



You can limite the risks by chmod'ing and changing owner of the file. But it's still not perfect.


----------



## Lobster (Jun 26, 2010)

Very happy right now!

but

1. this Expect lang is evil
 - It needs whole big string just to input "any string"

2. this book Exploring Expect is evil (but good even I with my poor english could understend it)
 - only on page 111 i find that realy needed

3. you are evil
 - why you did no say too me that i only need construction like this

```
#!/usr/local/bin/expect --

puts "Change password input user name:\n"
expect -re "(.*)\n" {
   set name $expect_out(1,string)
}
puts "input $name password:\n"   ;# smile hides  ": \ n" without space
expect -re "(.*)\n" {
   set password $expect_out(1,string)
}

spawn passwd $name
expect "New Password:"
send "$password\r"
expect "Retype New Password:"
send "$password\r"
expect eof
```

4. vi is evil 
 - why he does one step behind than editing or deleting something

5. Wather is evil
 - unsuported warm

I write this script (seen on string 3 higer) it woks, strange output but it works

in windows

```
@echo off
plink.exe -t -ssh 192.168.1.100 -l root -pw qwertty /usr/local/www/expect/6f
pause
```


```
Change password input user name:

u1
input u1 password:

12
spawn passwd u1
Changing local password for u1
New Password:
Retype New Password:
```

Uf i fink now i can write script for geom_eli to mount partition from windows exe file in one click (and too pass inputs of couse) on putty session

Thank you all ....brbrbr realy exousted all day finding solution!


----------



## DutchDaemon (Jun 26, 2010)

@lobster: Posting and Editing in the FreeBSD Forums. Use proper formatting.


----------



## Lobster (Jun 27, 2010)

Thank you ok!

I just found that all works without Expect if starts plink with "-t" Ð–"))))))))))))


----------

