Kurt Pfeifle
2002-May-20 19:03 UTC
[Samba] How can $VARIABLES be used inside smbclient -c'xyz' command strings?
Hi, being a total newbie in shellscripting and similar stuff, I am suffering from a brain freeze around the following problem: * I need to print (or transfer otherwise) to a WinNT box; * the files are send from inside a shellscript; * the script gets the filename on the commandline when started; * so the only knows it works on "$1"; * the problem is, that the original filename needs to be conserved when it arrives on the WinShare... Anyone with a suggestion? Thanks, Kurt
Kurt Pfeifle
2002-May-20 19:44 UTC
[Samba] Re: How can $VARIABLES be used inside smbclient -c'xyz' command strings?
Kurt Pfeifle wrote:> Hi, > > being a total newbie in shellscripting and similar stuff, I > am suffering from a brain freeze around the following problem: > > * I need to print (or transfer otherwise) to a WinNT box; > * the files are send from inside a shellscript; > * the script gets the filename on the commandline when started; > * so the only knows it works on "$1"; > * the problem is, that the original filename needs to be conserved > when it arrives on the WinShare... > > Anyone with a suggestion?What I tried is this: -------------------- export FILENAME=testfile.ps kde-bitshop:/home/kde4 > smbclient //transmeta/ljet5 -N -c 'put $FILENAME' added interface ip=10.160.16.45 bcast=10.160.31.255 nmask=255.255.240.0 Domain=[TUX-NET] OS=[Unix] Server=[Samba 2.2.4] $$FILENAME does not exist kde-bitshop:/home/kde4 > echo $FILENAME testfile.ps kde-bitshop:/home/kde4 > smbclient //transmeta/ljet5 -N -c "put $FILENAME" added interface ip=10.160.16.45 bcast=10.160.31.255 nmask=255.255.240.0 Domain=[TUX-NET] OS=[Unix] Server=[Samba 2.2.4] $FILENAME does not exist
Joel Hammer
2002-May-21 19:05 UTC
[Samba] Re: How can $VARIABLES be used inside smbclient -c'xyz' command strings?
IT LOOKS like the function doesn't have direct access to the command line variables, which I never knew, so just do this: Name1=$1 Name2=$2 And then subsitute $Name1 and $Name2 into the function. Meanwhile, I'll read about functions and the scope of variables. Joel On Wed, May 22, 2002 at 03:46:52AM +0200, Kurt Pfeifle wrote:> Joel Hammer wrote: > > Can you post a sample of your script wherein the $1 variable fails to be > > expanded to its value? > > Joel > > > > OK, here is a sample. > -------------------- > #!/bin/bash > #"testscript2" > cp $1 $1.kdk > echo $1 > echo $1.kdk > echo trying to send job $1 > echo trying to send job $1.kdk > smbclient //turbo/mopi240 -N -c "put $1;put $1.kdk" # this works > sendJob() { > echo trying to send job \(from inside a function\) $1 # this doesn't work > echo trying to send job \(from inside a function\) $1.kdk # this doesn't work > smbclient //turbo/mopi240 -N -c "put $1;put $1.kdk" # this doesn't work > echo "Exitstatus von smbclient $?" > } > sendJob > echo "Job sent?" > > > I get this output: > ------------------ > kde4@transmeta:~/JobTix> sh testscript2 testscript > testscript > testscript.kdk > trying to send job testscript > trying to send job testscript.kdk > INFO: Debug class all level = 3 (pid 8444 from pid 8444) > added interface ip=10.160.16.40 bcast=10.160.31.255 nmask=255.255.240.0 > added interface ip=172.16.158.1 bcast=172.16.158.255 nmask=255.255.255.0 > Got a positive name query response from 10.160.16.2 ( 10.160.16.2 ) > Domain=[SYSTEMSUPPORT] OS=[Windows NT 4.0] Server=[NT LAN Manager 4.0] > putting file testscript as \testscript (0.9 kb/s) (average 0.9 kb/s) > putting file testscript.kdk as \testscript.kdk (1.0 kb/s) (average 0.9 kb/s) > trying to send job (from inside a function) > trying to send job (from inside a function) .kdk > INFO: Debug class all level = 3 (pid 8445 from pid 8445) > added interface ip=10.160.16.40 bcast=10.160.31.255 nmask=255.255.240.0 > added interface ip=172.16.158.1 bcast=172.16.158.255 nmask=255.255.255.0 > Got a positive name query response from 10.160.16.2 ( 10.160.16.2 ) > Domain=[SYSTEMSUPPORT] OS=[Windows NT 4.0] Server=[NT LAN Manager 4.0] > put <filename> > .kdk does not exist > Job sent? > > > So the problem to solve is: how do I get the varibles $1 etc. get > recogized inside a shell function? > > [Probably easy -- but 5 hours of reading in a thick book abut shell programming > didn't let me find a solution yet. Ascribe it to my newbie-ness in such things, > please.] > > Thanks, > Kurt > > > > On Tue, May 21, 2002 at 05:55:14PM +0200, Kurt Pfeifle wrote: > > > >>Joel Hammer wrote: > >> > >>>Have you tried double quotes instead of single quotes. Single quotes prevent > >>>expansion of $1 to its value. > >>>Joel > >>> > >>> > >>Yes, that's why I explicitely named them "double" and "single" quotes, in case > >>they get not recognized as such by quickly scanning the email.... ;-) > >> > >>Kurt > >> > >> > >>>On Tue, May 21, 2002 at 01:35:22PM +0200, Kurt Pfeifle wrote: > >>> > >>> > >>>>Thanks, Joel, > >>>> > >>>>for your answer. It is not ftp, it is smbclient (which will be on HP-UX) > >>>>and the receiving end is a WinNT4 box. > >>>> > >>>>Joel Hammer wrote: > >>>> > >>>> > >>>>>Will the ftp box act as an ftp server? > >>>>>If so, an expect script might be a good way to transfer them. > >>>>> > >>>>> > >>>>> > >>>>Hmmm, "expect" is even more "new" to me than the shell scripting stuff... > >>>>I'll start reading the manpage tonight, and google for documentation, > >>>>tutorials and examples of expect scripts.. > >>>> > >>>> > >>>> > >>>>>This command worked fine for me: > >>>>>smbclient //HAMMER2/ELLEN -N -c "put junkheader.txt" > >>>>> > >>>>> > >>>>This works for me too, even in the form of using single quotes (') > >>>>instead of double ("). But here you *named* the file. > >>>> > >>>>*I* need to call it by its reference as a commandline parameter. > >>>> > >>>> > >>>> > >>>>>where junkheader.txt is a file on the local system. $1 should work. The > >>>>>original file name is preserved. > >>>>> > >>>>> > >>>>Maybe "preserved". But it is a kind of double nesting: $1 is recognized > >>>>inside the shell script; but then inside the script there is smbclient > >>>>called, and the "-c" (for commands to be executed by smbclient) needs > >>>>quotes and inside these quotes the $1 isn't recognized any more. > >>>> > >>>>I don't need to rely on smbclient, I just need a method to process a > >>>>file "file-orig" through a script (called as "script.sh file.orig"), > >>>>which generates a second file, "file-orig.extension", and then transfer > >>>>both to the NT box, preserving their names "file-orig" and > >>>>"file-orig.extension". > >>>> > >>>>[I succeeded to transfer by renaming the files "file.orig" to allways > >>>>the same name "new-static-name" and transfer the "new-static-name" to > >>>>the NT-box.... but that is not the purpose...] > >>>> > >>>>Thanks again, > >>>>Kurt > >>>> > >>>> > >>>> > >>>> > >>>>>Joel > >>>>> > >>>>>On Tue, May 21, 2002 at 04:36:39AM +0200, Kurt Pfeifle wrote: > >>>>> > >>>>> > >>>>> > >>>>>>Kurt Pfeifle wrote: > >>>>>> > >>>>>> > >>>>>> > >>>>>>>Hi, > >>>>>>> > >>>>>>>being a total newbie in shellscripting and similar stuff, I > >>>>>>>am suffering from a brain freeze around the following problem: > >>>>>>> > >>>>>>>* I need to print (or transfer otherwise) to a WinNT box; > >>>>>>>* the files are send from inside a shellscript; > >>>>>>>* the script gets the filename on the commandline when started; > >>>>>>>* so the only knows it works on "$1"; > >>>>>>>* the problem is, that the original filename needs to be conserved > >>>>>>>when it arrives on the WinShare... > >>>>>>> > >>>>>>>Anyone with a suggestion? > >>>>>>> > >>>>>>> > >>>>>>> > >>>>>>What I tried is this: > >>>>>>-------------------- > >>>>>> > >>>>>>export FILENAME=testfile.ps > >>>>>> > >>>>>>kde-bitshop:/home/kde4 > smbclient //transmeta/ljet5 -N -c 'put $FILENAME' > >>>>>>added interface ip=10.160.16.45 bcast=10.160.31.255 nmask=255.255.240.0 > >>>>>>Domain=[TUX-NET] OS=[Unix] Server=[Samba 2.2.4] > >>>>>>$$FILENAME does not exist > >>>>>> > >>>>>>kde-bitshop:/home/kde4 > echo $FILENAME > >>>>>>testfile.ps > >>>>>> > >>>>>>kde-bitshop:/home/kde4 > smbclient //transmeta/ljet5 -N -c "put $FILENAME" > >>>>>>added interface ip=10.160.16.45 bcast=10.160.31.255 nmask=255.255.240.0 > >>>>>>Domain=[TUX-NET] OS=[Unix] Server=[Samba 2.2.4] > >>>>>>$FILENAME does not exist > >>>>>> > >>>>>> > >>>>>>-- > >>>>>>To unsubscribe from this list go to the following URL and read the > >>>>>>instructions: http://lists.samba.org/mailman/listinfo/samba > >>>>>> > >>>>>> > >>>>>> > >> > > > >