LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 03-06-2012, 02:21 PM   #1
DirtyHowi
Member
 
Registered: Jan 2012
Posts: 34

Rep: Reputation: Disabled
Running Bash from inside VBS


Ok before you flay (or is that fillet) me, we have generated HTML files that our machine shop runs to make kits out of, they essentially put in a number of kits and hit the button and it prints it out.

there is a vbscript on my RHEL server that creates the file needed to print, a cron job then comes by and picks it up and does the rest (printing etc)

part of the script looks like this

Code:
sub WHSBuild(FileName)
	Dim fso, tf
	a = "\\MYSERVER\Updates\" & FileName & ".kitw"
	Set fso = CreateObject("Scripting.FileSystemObject")
	Set tf = fso.CreateTextFile(a, True )					
	i = KITFORM.length - 1
	for j = 0 to i step 5
		if KITFORM(j).value = FileName then
			dim answer			
			answer=MsgBox("A WHS Picking Report Will Be Generated - Qty:  " & KITFORM(j+1).value & (CHR(13)) & (CHR(13)) & "                                         ", 1, FileName)
			if answer = 1 then
				b = KITFORM(j).value & "," & KITFORM(j+1).value & "," & KITFORM(j+2).value & "," & "LABELS"
				tf.writeline(b)
			elseif answer = 7 then
				b = KITFORM(j).value & "," & KITFORM(j+1).value & "," & KITFORM(j+2).value & "," & "NOLABELS"
				tf.writeline(b)
			else
				b = "CANCEL"
				tf.writeline(b)
			end if 
		end if
	next
	tf.Close
i need to change the owner of the a file from within here to a certain person so the other jobs that run will out put it to the correct printer, i cant find where in VBS i can execute a SUDO CHOWN, but does anyone know if there is a way to execute a bash script from within the VBS file to change the ownership so it comes out in the right place?
 
Old 03-06-2012, 02:39 PM   #2
arizonagroovejet
Senior Member
 
Registered: Jun 2005
Location: England
Distribution: openSUSE, Fedora, CentOS
Posts: 1,094

Rep: Reputation: 198Reputation: 198
No idea how you'd do exactly what you ask, but you indicate there is a cronjob - assuming the script which is being called by the cronjob, could that do the chown? Alternatively could you put a wrapper around the VBS script

Code:
#!/bin/bash
whatever-it-is-you-do-to-run-the-vbs-script
sudo chown whatever
Alternatively have you tried approaching the problem from another angle? Is there not a neater way to control which printer the job goes to other than who owns the file? Fixing the problem of the job going to the wrong printer by having a script running a command via sudo seems sort of, well, wrong. I mean for an automated (right?) script to be able to run a command via sudo it has to be able to do so without a password, which means setting up sudo to allow that and so on.

I realise I'm not answering your actual question, but sometimes the best solution to a problem isn't where one first looks for it.
 
Old 03-06-2012, 03:14 PM   #3
DirtyHowi
Member
 
Registered: Jan 2012
Posts: 34

Original Poster
Rep: Reputation: Disabled
the script is part of a HTML document that they have a short cut to. right now its giving nobody:nobody, on UNIX it used to catch the user login and use that.

the cron job comes around after the file has been created and does further processing.
 
Old 03-06-2012, 08:27 PM   #4
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
How about the VBS (which presumably knows the user name that the file should be chowned to) appending that name to the end of the file and the cron job (now a script, if not before) reading that information, stripping it and chowning as required?

BTW how are you running VBS on RHEL? Knowing that might lead to more elegant solutions.
 
Old 03-06-2012, 09:40 PM   #5
DirtyHowi
Member
 
Registered: Jan 2012
Posts: 34

Original Poster
Rep: Reputation: Disabled
i dont purport to know HOW, althouth all they really are doing is looking to a web page in a directory on RHEL and since all HTML scripting is client side it really isnt running there, just kinda hanging out.

there is a javascript file that generates the web page information in there as well, and then when you put the number in the box and hit the button it calls the function i posted originally. and since the vbs points the text file at RHEL it just writes it there, the directory is a samba share so windows dont see it as anything different or other than another windows shared folder.

the only other thing i can think to do is possibly pass the username via a session variable or something similar.

and the page does not know the linux username, if it did it wouldnt save the files as nobody:nobody
 
Old 03-06-2012, 09:46 PM   #6
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Thanks for the explanation; clearer now.

Is the "certain person" always the same one and, if not, on which system (browser client, web server, samba server, ...) is the "certain person" known -- and how is it known?
 
Old 03-06-2012, 10:42 PM   #7
elfenlied
Member
 
Registered: Dec 2004
Posts: 83

Rep: Reputation: 8
This is what I'm getting from your posts:

* You have a RHEL web server
* That webserver has a HTML page which has some VBS scripting on it.
* The VBS script writes to a file on a samba server

Now from your vbs's point of view, it doesn't know that the server you're writing it to is a samba server, all it knows its a Windows share. So can you just treat is at a Windows share and change permissions the same way you would a Windows share?

Since you say all the vbs is client side for any kind of linux commands to work this script would need to run server side or the required commands (ie chown) would need to be available on the client machine thats executing the script.

Alternatively I came across this which is similar in some ways ... http://stackoverflow.com/questions/6...lesystemobject. To get around the fact that fso "it always runs with the credentials of the application using it". It looks messy especially since you have to put in a username / password in the script but that might give you something to work from.
 
Old 03-07-2012, 07:53 AM   #8
DirtyHowi
Member
 
Registered: Jan 2012
Posts: 34

Original Poster
Rep: Reputation: Disabled
its not a web server, we just create a shortcut to the HTML file on RHEL and it runs locally in IE. (i know i know). Its just a table that gets filled out by the javascript thats there. i know the "name" of the file and the user is the same guy all the time (or could be even if he leaves wouldnt' matter) i just need to chown that text file to user:user rather than nobody:nobody, thought if i could run a bash script and pass it the file name a simple sudo chown user:user $file would work.
 
Old 03-07-2012, 08:17 AM   #9
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
It would be nice to have answers to the questions intended to elucidate your application architecture and the sequence of actions.

Still guessing what that is ...

You could use inotify to watch the directory where the file is created and run something to chown new files.
 
Old 03-07-2012, 11:06 AM   #10
DirtyHowi
Member
 
Registered: Jan 2012
Posts: 34

Original Poster
Rep: Reputation: Disabled
HTML file and script files exist in directory directory is samba shared on RHEL box.
user has shortcut to HTML file on RHEL box.
user clicks shortcut to open HTML file on local machine.
user fills in information necessary pushes button on HTML page.
VBS script creates text file and saves it to local RHEL directory.
cron job comes around and prints the necessary forms based on user.
currently file is being saved with nobody:nobody ownership, which appears to be the samba service (which makes sense)
need to have file chown'd by user:user not nobody:nobody so it comes out on the appropriate printers (user is mapped to certain printers in their area).
 
Old 03-07-2012, 05:46 PM   #11
elfenlied
Member
 
Registered: Dec 2004
Posts: 83

Rep: Reputation: 8
Couldn't you just add the relevant chown to your cron job? So that it does that before it prints the files off?
 
Old 03-14-2012, 10:47 AM   #12
DirtyHowi
Member
 
Registered: Jan 2012
Posts: 34

Original Poster
Rep: Reputation: Disabled
this has to do with samba and not picking up the user from AD and matching it to a linux user name.

facetwin did this automatically, samba does not. the HTML files are just that HTML form docs that are run from a shortcut to them on the desktop, the VBS that creates the text/other files resides there too, just for consistancy, since all the client machines are windows based, when they click the shortcut it opens the HTML document client side and executes the scripts when they hit the button (again client side).

facetwin (which we had on our old unix box) had an alias file that it would check to write the appropriate user name to the file for the owner, samba does not do this instead it uses nobody, we then do a ls -l > file on the directory and read file in cobol to extract the username and file name then generate the actual doc in cobol and send it along.

so the question becomes how do i get samba to pick up that, there is no samba-alias file to use.
 
Old 03-23-2012, 09:37 AM   #13
DirtyHowi
Member
 
Registered: Jan 2012
Posts: 34

Original Poster
Rep: Reputation: Disabled
since only one person used this, we simply changed the extension from .txtk to .asyk and then picked that up as a special case in the printing routine, works great and the customer is happy. ultimately simple solution to an otherwise complex problem.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Using an alias inside a function in bash martindl Linux - Newbie 1 06-08-2011 11:55 PM
running XP from inside Incognito Sylvester Incognito 3 08-01-2009 09:09 AM
bash: if block inside select' agrestic Linux - Software 1 01-14-2009 04:01 PM
using su inside a bash file elie nasrani Linux - Newbie 3 08-22-2007 09:10 PM
[Bash] Command inside a variable yvovandoorn Programming 5 01-20-2007 06:48 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 06:58 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration