Adding a printer using vbscript ... expected end of statement - printing

Even though I appear to write it as pretty much all the examples on the web, I still have this error.
Here, take a look... http://i.imgur.com/1TqL52V.png
My code is as follows (in case you didn't take a look):
cscript "C:\Windows\System32\Printing_Admin_Scripts\en-US\prnport.vbs" -a -r "C70 PS Driver" -h 13.226.51.135 -o raw -n 9200
cscript "C:\Windows\System32\Printing_Admin_Scripts\en-US\prndrvr.vbs" -a -v 3 -m "Xerox Color C70 PS" -i "C:\Xerox_C70_2014_11\XCC70_5.382.4.0_PS_x64_Driver.inf\x2GITHP.inf" -h "C:\Xerox_C70_2014_11\XCC70_5.382.4.0_PS_x64_Driver.inf"
cscript "C:\Windows\System32\Printing_Admin_Scripts\en-US\prnmngr.vbs" -a -p "Xerox Color C70 PS" -m "Xerox Color C70 PS" -r "C70 PS Driver"
The error is at line 1, and says:
Microsoft (R) Windows Script Host Version 5.8
Copyright (C) Microsoft Corporation. All rights reserved.
C:\Users\Antoine\AppData\Local\Adersoft\VbsEdit\Temp\MMNPNCCZ.vbs(1, 78) Microsoft VBScript >compilation error: Expected end of statement
***** script completed - exit code: 1 *****
Edit: Here's the content of the file (C:\Users\Antoine\AppData\Local\Adersoft\VbsEdit\Temp\MMNPNCCZ.vbs)
cscript "C:\Windows\System32\Printing_Admin_Scripts\en-US\prnport.vbs" -a -r "C70 PS Driver" -h 13.226.51.135 -o raw -n 9200
cscript "C:\Windows\System32\Printing_Admin_Scripts\en-US\prndrvr.vbs" -a -v 3 -m "Xerox Color C70 PS" -i "C:\Xerox_C70_2014_11\XCC70_5.382.4.0_PS_x64_Driver.inf\x2GITHP.inf" -h "C:\Xerox_C70_2014_11\XCC70_5.382.4.0_PS_x64_Driver.inf"
cscript "C:\Windows\System32\Printing_Admin_Scripts\en-US\prnmngr.vbs" -a -p "Xerox Color C70 PS" -m "Xerox Color C70 PS" -r "C70 PS Driver"
I have to say, its my first time trying to script this, so yes, I'm new to this.
In any case, all comments are welcomed.
Thank you,

Rename MMNPNCCZ.vbs to MMNPNCCZ.bat. You can't run commands from VBScript like that.
#echo off
rem MMNPNCCZ.bat
cscript "C:\Windows\System32\Printing_Admin_Scripts\en-US\prnport.vbs" -a -r "C70 PS Driver" -h 13.226.51.135 -o raw -n 9200
cscript "C:\Windows\System32\Printing_Admin_Scripts\en-US\prndrvr.vbs" -a -v 3 -m "Xerox Color C70 PS" -i "C:\Xerox_C70_2014_11\XCC70_5.382.4.0_PS_x64_Driver.inf\x2GITHP.inf" -h "C:\Xerox_C70_2014_11\XCC70_5.382.4.0_PS_x64_Driver.inf"
cscript "C:\Windows\System32\Printing_Admin_Scripts\en-US\prnmngr.vbs" -a -p "Xerox Color C70 PS" -m "Xerox Color C70 PS" -r "C70 PS Driver"
If you must do it in VBScript you'd need something like this:
' MMNPNCCZ.vbs
Set sh = CreateObject("WScript.Shell")
sh.Run "cscript ""C:\Windows\System32\Printing_Admin_Scripts\en-US\prnport.vbs"" -a -r ""C70 PS Driver"" -h 13.226.51.135 -o raw -n 9200", 0, True
sh.Run "cscript ""C:\Windows\System32\Printing_Admin_Scripts\en-US\prndrvr.vbs"" -a -v 3 -m ""Xerox Color C70 PS"" -i ""C:\Xerox_C70_2014_11\XCC70_5.382.4.0_PS_x64_Driver.inf\x2GITHP.inf"" -h ""C:\Xerox_C70_2014_11\XCC70_5.382.4.0_PS_x64_Driver.inf""", 0, True
sh.Run "cscript ""C:\Windows\System32\Printing_Admin_Scripts\en-US\prnmngr.vbs"" -a -p ""Xerox Color C70 PS"" -m ""Xerox Color C70 PS"" -r ""C70 PS Driver""", 0, True

Related

docker pg_restore stdin with powershell core

I try to translate this command with Powershell Core
docker run --rm -e PGPASSWORD=$Env:PGPASSWORD postgres:14.2 pg_restore --clean -d db -h mydb.com -U sa --format=custom < pg.dump
And I have this error
The '<' operator is reserved for future use.
I've tried many things like
echo pg.dump | docker run --rm -e PGPASSWORD=$Env:PGPASSWORD postgres:14.2 pg_restore --clean -d db -h mydb.com -U sa --format=custom
pg_restore: error: could not read from input file: end of file
echo pg.dump | docker run --rm -e -it PGPASSWORD=$Env:PGPASSWORD postgres:14.2 pg_restore --clean -d db -h mydb.com -U sa --format=custom
the input device is not a TTY. If you are using mintty, try prefixing the command with 'winpty'
I can't find how to use the stdin operator with Powershell Core
Try to change sequence of your actions. Run container -> Copy backup file into container -> Run command pg_restore
Here is an algorithm (not the working code) to execute in powershell. Note that docker cp may work only with container id. You can get it if you parse it via docker ps | Select-String -Pattern "my_postgres"
Set-Location "C:\postgres_backup"
Write-Output "Starting postgres container"
docker run --rm --name=my_postgres --env PGPASSWORD=$Env:PGPASSWORD postgres:14.2
Write-Output "Copying backup to container"
docker cp ./pg.dump my_postgres:/pg.dump
Write-Output "Execute something in postgres container"
docker exec -i $my_postgres pg_restore --clean -d db -h mydb.com -U sa --format=custom -1 pg.dump

How to hide data displayed on the terminal while executing tshark?

I need to hide data that is displayed while executing tshark command line for wireshark:
tshark -i tun0 -T ek -w /home/PCAP_Folder/Sim_Run1st.pcap
I am running two program simultaneously
The following will send the output to /dev/null:
tshark -i tun0 -T ek -w /home/PCAP_Folder/Sim_Run1st.pcap > /dev/null
If you also want to hide any error message:
tshark -i tun0 -T ek -w /home/PCAP_Folder/Sim_Run1st.pcap &> /dev/null
Note that if you also hide the error messages, the -T ek option becomes pointless.

Why exited docker conatiner are not getting removed?

File name: dockerHandler.sh
#!/bin/bash
set -e
to=$1
shift
cont=$(docker run -d "$#")
code=$(timeout "$to" docker wait "$cont" || true)
docker kill $cont &> /dev/null
docker rm $cont
echo -n 'status: '
if [ -z "$code" ]; then
echo timeout
else
echo exited: $code
fi
echo output:
# pipe to sed simply for pretty nice indentation
docker logs $cont | sed 's/^/\t/'
docker rm $cont &> /dev/null
But whenever I check the docker container status after running the the docker image it is giving list of exited docker containers.
command: docker ps -as
Hence to delete those exited containers I am running manually below command
rm $(docker ps -a -f status=exited -q)
You should add the flag --rm to your docker command:
From Docker man:
➜ ~ docker run --help | grep rm
--rm Automatically remove the container when it exits
removed lines
docker kill $cont &> /dev/null
docker rm $cont
docker logs $cont | sed 's/^/\t/'
and used gtimeout instead timeout in Mac, it works fine.
To install gtimeout on Mac:
Installing CoreUtils
brew install coreutils
In line 8 of DockerTimeout.sh change timeout to gtimeout

Scripts for printer configuration mono / color - Windows 7

I've been working on this for some time and nearly got it working. Nearly....
I am creating a script under Win7 Ent that's adding 2 network printers (no printer server - just via IP address). For each printer I want it to create a colour and mono queue - so 4 printer queues in total.
Adding works fine with those commands:
cscript "C:\XXXXX\Scripts\Prnmngr.vbs" -d -p "XXX_Operators_Color"
cscript "C:\XXXXX\Scripts\Prnmngr.vbs" -d -p "XXX_Operators_MOno"
cscript "C:\XXXXX\Scripts\Prnmngr.vbs" -d -p "XXX_Traders_Color"
cscript "C:\XXXXX\Scripts\Prnmngr.vbs" -d -p "XXX_Traders_MOno"
cscript "C:\XXXXX\Scripts\Prnport.vbs" -d -r IP_XXX.XXX.XXX.116mono
cscript "C:\XXXXX\Scripts\Prnport.vbs" -d -r IP_XXX.XXX.XXX.116color
cscript "C:\XXXXX\Scripts\Prnport.vbs" -d -r IP_XXX.XXX.XXX.118mono
cscript "C:\XXXXX\Scripts\Prnport.vbs" -d -r IP_XXX.XXX.XXX.118color
cscript "C:\XXXXX\Scripts\Prnmngr.vbs" -d -p "XXX_Operators_Color"
cscript "C:\XXXXX\Scripts\Prnmngr.vbs" -d -p "XXX_Operators_MOno"
cscript "C:\XXXXX\Scripts\Prnmngr.vbs" -d -p "XXX_Traders_Color"
cscript "C:\XXXXX\Scripts\Prnmngr.vbs" -d -p "XXX_Traders_MOno"
cscript "C:\XXXXX\Scripts\Prnport.vbs" -d -r IP_XXX.XXX.XXX.116mono
cscript "C:\XXXXX\Scripts\Prnport.vbs" -d -r IP_XXX.XXX.XXX.116color
cscript "C:\XXXXX\Scripts\Prnport.vbs" -d -r IP_XXX.XXX.XXX.118mono
cscript "C:\XXXXX\Scripts\Prnport.vbs" -d -r IP_XXX.XXX.XXX.118color
cscript "C:\XXXXX\Scripts\Prnport.vbs" -a -r IP_XXX.XXX.XXX.116mono -h XXX.XXX.XXX.116 -o raw -n 9100
cscript "C:\XXXXX\Scripts\Prnport.vbs" -a -r IP_XXX.XXX.XXX.116color -h XXX.XXX.XXX.116 -o raw -n 9100
cscript "C:\XXXXX\Scripts\Prnport.vbs" -a -r IP_XXX.XXX.XXX.118mono -h XXX.XXX.XXX.118 -o raw -n 9100
cscript "C:\XXXXX\Scripts\Prnport.vbs" -a -r IP_XXX.XXX.XXX.118color -h XXX.XXX.XXX.118 -o raw -n 9100
cscript "C:\XXXXX\Scripts\Prndrvr.vbs" -a -m "HP Universal Printing PCL 6" -i C:\XXXXX\Drivers\hpzius23.inf
cscript "C:\XXXXX\Scripts\Prnmngr.vbs" -a -p "XXX_Traders_Color" -m "HP Universal Printing PCL 6" -r IP_XXX.XXX.XXX.116color
cscript "C:\XXXXX\Scripts\Prnmngr.vbs" -a -p "XXX_Traders_MOno" -m "HP Universal Printing PCL 6" -r IP_XXX.XXX.XXX.116mono
cscript "C:\XXXXX\Scripts\Prnmngr.vbs" -a -p "XXX_Operators_Color" -m "HP Universal Printing PCL 6" -r IP_XXX.XXX.XXX.118color
cscript "C:\XXXXX\Scripts\Prnmngr.vbs" -a -p "XXX_Operators_MOno" -m "HP Universal Printing PCL 6" -r IP_XXX.XXX.XXX.118mono'
I hit a wall when trying to set the queues with color / mono setting.
Tried two methods:
Via Powershell Set-PrintConfiguration command:
Set-PrintConfiguration –PrinterName "XXX_Traders_Color" -Color "1"
Set-PrintConfiguration –PrinterName "XXX_Traders_MOno" -Color "0"
Set-PrintConfiguration –PrinterName "XXX_Operators_Color" -Color "1"
Set-PrintConfiguration –PrinterName "XXX_Operators_MOno" -Color "0"
I'm getting below (guessing this is not a command present in Win 7 powershell):
The term 'Set-PrintConfiguration' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and
try again.
I tried using the RUNDLL32 PRINTUI.DLL,PrintUIEntry commands to
export printer configuration with changed mono / color setting (works fine)
RUNDLL32 PRINTUI.DLL,PrintUIEntry /Ss /n "XXX_Operators_MOno" /a "c:\temp\Mirek1.dat" d g
import the file created above into new queue:
RUNDLL32 PRINTUI.DLL,PrintUIEntry /Sr /n "NewXXX_Operators_MOno" /a "c:\temp\Mirek1.dat"
But the second command doesn't seem to cause the queue to adjust mono / color setting that was exported in the first instance.
I wonder if anyone here has struggled with similar headache?
Any help much appreciated..
I got this to work by using the u switch (instead of d g). That exports "User DevMode":
RUNDLL32 PRINTUI.DLL,PrintUIEntry /Ss /n "XXX_Operators_MOno" /a "c:\temp\Mirek1.dat" u

Error on script to clear cache docker container

I need to clear cache manually in my nginx docker container and would make a script, i have make a script that found the PID:
docker-pid
#!/bin/sh
exec docker inspect --format '{{ .State.Pid }}' "$#"
And another final script
clear_cache.sh
#!/bin/sh
PID=/usr/bin/docker-pid proxy_nginx_1
nsenter -m -p -u -n -i -t $PID
rm -rf /etc/nginx/cache/*
exit
I get this error:
./clear_cache.sh: line 2: proxy_nginx_1: command not found
if i launch docker-pid to shell, it works....Why?
In bash you have to use $(<COMMAND>) if you want to save the output of a command to a variable. So
clear_cache.sh
#!/bin/sh
PID=$(/usr/bin/docker-pid proxy_nginx_1)
nsenter -m -p -u -n -i -t $PID
rm -rf /etc/nginx/cache/*
exit
or
#!/bin/sh
PID=$(docker inspect --format '{{ .State.Pid }}' "$#")
nsenter -m -p -u -n -i -t $PID
rm -rf /etc/nginx/cache/*
exit

Resources