executing batch file from snapin
-
@Olduser Do you have the Batch file you originally uploaded? Please post that, or even just the source code directly. Telling us the same thing over and over isn’t helping much.
We need to know what your script is trying to do, and why it’s not doing what you’re expecting it to do.
-
@Olduser As @Joe-Schmitt and others have said,
C:\program Files\FOG\tmp
is temporary.Files in that directory are not permanent. As soon as the snapin is complete, files in there are immediately deleted forever. Gone. Purged.
Please post a copy of your script so we can help you more.
-
Tom,
Thank You very much for reply. I am also trying to figure out why snapin will install the batch script sometimes and other time nothing happens. I see a message that "Test installed " on taskbar but when I go to C:\Program Files\FOG\tmp, it is empty. If I run script manually, it run without any problem. I see copy file in C:\Temp directory.
The batch script does this:
Thanks,
Olduser -
@Olduser If it was me, I would create some conditional tests.
Does the S: drive exist
Does the user account running this batch copy script have user rights to S:
Does the path S:\PAT exist
Does the file tdpunt.bat exist in the path S:\PAT
Does the C:\Temp path exist, if not then create it
Write the negative results of your tests to a log file in C:\Temp to help you figure out what went wrong. -
Tom,
I am also pasting fog log below:
----------------------------------------------------------------------------- ---------------------------------SnapinClient--------------------------------- ------------------------------------------------------------------------------ 1/6/2017 11:32 AM Client-Info Client Version: 0.11.7 1/6/2017 11:32 AM Client-Info Client OS: Windows 1/6/2017 11:32 AM Client-Info Server Version: 1.3.0-RC-37 1/6/2017 11:32 AM Middleware::Response Success 1/6/2017 11:32 AM SnapinClient Snapin Found: 1/6/2017 11:32 AM SnapinClient ID: 291 1/6/2017 11:32 AM SnapinClient Name: test 1/6/2017 11:32 AM SnapinClient Created: 2017-01-06 16:32:21 1/6/2017 11:32 AM SnapinClient Action: 1/6/2017 11:32 AM SnapinClient Pack: False 1/6/2017 11:32 AM SnapinClient Hide: False 1/6/2017 11:32 AM SnapinClient Server: 1/6/2017 11:32 AM SnapinClient TimeOut: 0 1/6/2017 11:32 AM SnapinClient RunWith: cmd.exe 1/6/2017 11:32 AM SnapinClient RunWithArgs: /c 1/6/2017 11:32 AM SnapinClient Args: 1/6/2017 11:32 AM SnapinClient File: test.bat 1/6/2017 11:32 AM Middleware::Communication Download: http://10.106.12.197/fog/service/snapins.file.php?mac=18:03:73:E6:62:43||00:00:00:00:00:00:00:E0&taskid=291 1/6/2017 11:32 AM SnapinClient C:\Program Files\FOG\tmp\test.bat 1/6/2017 11:32 AM Bus { "self": true, "channel": "Notification", "data": "{\r\n \"title\": \"Installing test\",\r\n \"message\": \"Please do not shutdown until this is completed\"\r\n}" } 1/6/2017 11:32 AM Bus Emmiting message on channel: Notification 1/6/2017 11:32 AM SnapinClient Starting snapin... 1/6/2017 11:32 AM SnapinClient Snapin finished 1/6/2017 11:32 AM SnapinClient Return Code: 0 1/6/2017 11:32 AM Bus { "self": true, "channel": "Notification", "data": "{\r\n \"title\": \"test Installed\",\r\n \"message\": \"Installation has finished and is now ready for use\"\r\n}" } 1/6/2017 11:32 AM Bus Emmiting message on channel: Notification 1/6/2017 11:32 AM Middleware::Communication URL: http://10.106.12.197/fog/service/snapins.checkin.php?taskid=291&exitcode=0&mac=18:03:73:E6:62:43||00:00:00:00:00:00:00:E0&newService&json ------------------------------------------------------------------------------
-
I would suggest using the full path of the file in your batch script instead of changing the directory.
And when I say full path, I mean the true full path, not the mounted S:\ drive.
Even if S:\ is being mounted by active directory or is a mapped drive as part of your image, I would still suggest using the full network/unc path.
I would also suggest mounting it with net use and a username and password. This will ensure the system account that the Fog Service uses has access to the files you want
I would also add some logging and other error preventions.i.e. if S:\ was mapped to \FileServer\Share …
@ECHO off echo. Create variables to make scripting easier set sharePath=\\FileServer\Share\Pat echo. Mount S drive path, replace username and password with share credentials. echo. If share is public omit the /USER parameter and everything after it net use %sharePath% /USER:username password echo. make sure destination exists, create it if it doesn't if not exist C:\temp mkdir C:\temp echo. copy each file, add /Y to overwrite without any prompt echo. copying tdpunt... copy /Y %sharePath%\tdpunt.bat C:\temp\ > C:\temp\tdpunt-bat-Copy.log echo. copying tundpt.exe... copy /Y %sharePath%\tundpt.exe C:\temp\ > C:\temp\tundpt-exe-Copy.log echo. Done! exit
Use that and then see if the .log files show up after deploying the snapin.
Also, in the web gui snapin config, you should take out the /qn that does nothing.
The snapin arguments section is for custom arguments that you have in your script. Your script doesn’t do anything with the /qn and it could cause issues. The /c parameter is passed to the cmd.exe command which tells cmd.exe to open a prompt, run the command, and then close.
If you had a line in your script like thisif "%1" == "/qn" ( echo. hey look a parameter, lets do something since it's there! )
then the /qn would have a point.
Hope that helps a bit.
Thanks,
-JJ -
@JJ-Fullmer Well done!! I wish I could upvote your post more that just +1.
-
@george1421 Oh darn, I meant to also mention you in that comment saying that you were right and I was taking it a step further. So pretend I did that, and no I don’t know what an edit button is.
-
@george1421 And thank you good sir.
-
@JJ-Fullmer The only tweak I might suggest to your excellent code is that you could make the password for the share a batch variable like %1 and then pass that from answer from FOG so the password never exists in the batch script at all in case it was left behind for some reason after the snapin exited. It would be passed from FOG (assuming you can add switch variables inside the snapin setup). That part I don’t know because I don’t personally use snapins. Either way you could probably call the batch file with
cmd.exe /c test.bat password
and that should do it. -
TL;DR; Looking in the FOG installation tmp folder for where your script is running is not how your script is logically written. You should check the
C:\Temp
folder. (Maybe it’s not doing what you want because theC:\Temp
folder doesn’t event exist?)I think this is what’s interesting to me.
First, the messages of:
@Olduser said in executing batch file from snapin:but when I go to C:\Program Files\FOG\tmp, it is empty. If I run script manually, it run without any problem. I see copy file in C:\Temp directory.
You’re confusing yourself, as well as us, with the insistence of
when i go to C:\Program Files\FOG\tmp
As already stated numerous times, the C:\Program Files\FOG\tmp (or C:\Program Files (x86)\FOG\tmp) is the temporary holding point for the snapin being downloaded (then executed). Once the snapin is complete with installation the files used are cleaned up. This means the file will no longer exist.
The Confusion, I believe, is you may be checking the wrong place to see if the snapin did, or didn’t, work properly. Items 1-2 are kind of hand-in-hand.
- Does the C:\Temp folder exist on the system? (Maybe before you try copying you should add
mkdir %SYSTEMDRIVE%\Temp
) - Is the drive letter for your OS (I’d recommend changing the portion to
%SYSTEMDRIVE%
) - When checking if the snapin did what you want make sure you’re looking in the place the script is trying to write to. (In your case it’s currently
C:\Temp
) It will not exist in the FOG\tmp folder except when it’s downloading and executing. That and your script is NOT writing anything to the FOG\tmp.
- Does the C:\Temp folder exist on the system? (Maybe before you try copying you should add
-
Tom & JJ,
Thank you for your help. I will make changes to batch script and add full path to networkdrive and modify my script as you both suggested. On last Friday before going home. I un-installed the FOG client on PC , re-installed it and my batch script was there. I waited for about 1/2 hours to see if this file gets deleted from C:\Program Files\FOG\temp folder but it was still there. I will follow your suggestions and let to you know.
Thanks,
Olduser