I am trying to send out email attachment periodically from a batch script using this command line client
http://caspian.dotconf.net/menu/Software/SendEmail
the command for it is pretty straightforward
sendEmail -t abc#gmail.com -u hellp -f abd#nus.edu.sg -m world -s smtp.nus.edu.sg -xu nusstu\a123456 -xp helloworld! -a C:\Users\ll\Desktop\Quotes.docx
The strange thing is if I type that line in command prompt, it works perfectly fine. I can
receive the email with attachment.
However, when I put it into a batch script, like
:email
sendEmail -t abc#gmail.com -u hellp -f abd#nus.edu.sg -m world -s smtp.nus.edu.sg -xu nusstu\a123456 -xp helloworld! -a C:\Users\ll\Desktop\Quotes.docx
goto:eof
and I call this subroutine in my batch file, the output says
SMTP:AUTH authentication to smtp.nus.edu.sg:25 failed.
I checked. no typo, Could someone help me what is the difference? why the same command works in command line but cause trouble in a script file?
Thanks
I believe you're censoring your batch too much.
Try running the following:
#ECHO OFF
setlocal
echo sendEmail -t abc#gmail.com -u hellp -f abd#nus.edu.sg -m world -s smtp.nus.edu.sg -xu nusstu\a123456 -xp helloworld! -a C:\Users\ll\Desktop\Quotes.docx
endlocal
SETLOCAL enabledelayedexpansion
echo sendEmail -t abc#gmail.com -u hellp -f abd#nus.edu.sg -m world -s smtp.nus.edu.sg -xu nusstu\a123456 -xp helloworld! -a C:\Users\ll\Desktop\Quotes.docx
echo sendEmail -t abc#gmail.com -u hellp -f abd#nus.edu.sg -m world -s smtp.nus.edu.sg -xu nusstu\a123456 -xp helloworld^^! -a C:\Users\ll\Desktop\Quotes.docx
goto:eof
Because your password contains !, batch interprets that as a variable-name if DELAYEDEXPANSION is invoked. Since the variablename isn't set, it's replaced by [nothing] and sendtoemail believes that your password is helloworld\Users\ll\Desktop\Quotes.docx - hence the error message.
Related
This works for me.
$puda_TBList=(isql -S $DSQuery -U $User -P $PW -w 200 -D $DB -b -i $SQLDir\Get_TBList.sql)
But what I want to do is embed a variable in the initial variable name like this.
$($DB)_TBList=(isql -S $DSQuery -U $User -P $PW -w 200 -D $DB -b -i $SQLDir\Get_TBList.sql) where $DB is a variable within a FOR loop and I just can't make it work.
Is there an easy way to do this?
I tried all of these and got erros.
$($DB)_TBList=(isql -S $DSQuery -U $User -P $PW -w 200 -D $DB -b -i $SQLDir\Get_TBList.sql)
$($("$DB"_TBList)=(isql -S $DSQuery -U $User -P $PW -w 200 -D $DB -b -i $SQLDir\Get_TBList.sql)
$($DB)_TBList)=(isql -S $DSQuery -U $User -P $PW -w 200 -D $DB -b -i $SQLDir\Get_TBList.sql)
"$($DB)_TBList"=(isql -S $DSQuery -U $User -P $PW -w 200 -D $DB -b -i $SQLDir\Get_TBList.sql)
I want to use sendEmail to send automated emails.
If i run the following line separately it works:
sendemail.exe -f "payslip#dgroup.com" -t "dn.john#dgroup.com" -u "Payslip: DN JOHN, marca 1567, may 2021" -o message-file=mail_body_payslip.txt -o tls=no -o username="payslip#dgroup.com" -o password="hfsjfb&^%" -s webmail.dgroup.com:26 -o timeout=5 -xu payslip#dgroup.com -xp hfsjfb&^% -a "C:\Payslips\encrypted\2021_05_1702_DN_JOHN.pdf" -l email_log.txt
However if i try to run it from a bat file it doesn't work.
Here is the bat file:
#echo.
#echo.
echo Starting email session... >> email_log.txt
date /t >> email_log.txt
time /t >> email_log.txt
#echo.
#echo Verifying files...
#echo.
#echo Sending mails...
sendemail.exe -f "payslip#dgroup.com" -t "dn.john#dgroup.com" -u "Payslip: DN JOHN, marca 1567, may 2021" -o message-file=mail_body_payslip.txt -o tls=no -o username="payslip#dgroup.com" -o password="hfsjfb&^%" -s webmail.dgroup.com:26 -o timeout=5 -xu payslip#dgroup.com -xp hfsjfb&^% -a "C:\Payslips\encrypted\2021_05_1702_DN_JOHN.pdf" -l email_log.txt
#echo.
#echo.
#echo Payslip was sent. Verify email_log.txt
#echo.
#pause
When i run the bat file I get the following error:
Jun 16 14:01:55 srv3 sendemail.exe[2532]: ERROR => Connection attempt to localhost:25 failed: IO::Socket::INET: connect: Unknown error
If I run telnet localhost:25 I get this:
Could not open connection to the host, on port 23: Connect failed
What could be the problem? Why is running fine separately but executed from bat file I get error?
I've found the problem.
When you run the bat file the "%" character found in the password was replaced with "26" therefore the password was incorrect.
The solution is to use %% instead of %.
Two %% equals to one %.
I'm trying to create an automated backup in Postgresql using below link, but I don't know where to find the needed dll, I'm stuck here. Can't proceed to next instruction because of this. Can anyone knows how to do it? Need help please.
https://wiki.postgresql.org/wiki/Automated_Backup_on_Windows
comerr32.dll
gssapi32.dll
k5sprt32.dll
krb_32.dll
libeay32.dll
libiconv2.dll
libpq.dll
Microsoft.VC80.CRT.manifest
msvcm80.dll
msvcp80.dll
msvcr80.dll
pg_dump.dll
ssleay32.dll
zlib1.dll
Here's batch file script:
#echo off
for /f "tokens=1-4 delims=/ " %%i in ("%date%") do (
set dow=%%i
set month=%%j
set day=%%k
set year=%%l
)
set datestr=%month%_%day%_%year%
echo datestr is %datestr%
set BACKUP_FILE=<backup_name_>_%datestr%.backup
echo backup file name is %BACKUP_FILE%
SET PGPASSWORD=<password>
echo on
bin\pg_dump -i -h <localhost> -p 5432 -U <postgres> -F c -b -v -f %BACKUP_FILE% <db_name>
Is there missing syntax?
When manually executed error shows:
bin\pg_dump: illegal option -- i
I execute something like this
pg_dump.exe -h %SERVER% -p 5432 -U postgres -Fc -d %basedatos% -v -f %filebackup%
This variables replace value respective.
I wrote a shell script to create a data dump of records updated yesterday using mongoexport command.
yesterday=$(date -d 'yesterday 00:00:00' '+%s'000)
today=$(date -d 'today 00:00:00' '+%s'000)
query="'{\"updated_at\":{\$gte:new Date(${yesterday}),\$lte:new Date(${today})}}'"
echo ${query}
mongoexport -h $HOST -d $DOC -c $COL_NAME -u $USER -p $PWD -q ${query} -o $fileName
After adding query, when I run the shell script I get below error in console
'{"updated_at":{$gte:new Date(1484287200000),$lte:new Date(1484373600000)}}'
too many positional arguments: [Date(1484287200000),$lte:new Date(1484373600000)}}']
try 'mongoexport --help' for more information
When I run this query in command line it works properly. Can someone pls let me know why is this error when ran in shell script?
This works in command line.
$mongoexport -h <<HOST>> -d <<DOC>> -c <<COL> -u <<UN>> -p <<PWD>> -q '{"updated_at":{"$gte":new Date(1484287200000),"$lte":new Date(1484373600000)}}'
There is a rule of thumb in bash: when you use a variable, always surround it with double quotes. There are exceptions, but they are rare.
mongoexport -h "$HOST" -d "$DOC" -c "$COL_NAME" -u "$USER" -p "$PWD" -q "${query}" -o "$fileName"
This code worked for me
yesterday=$(date -d 'yesterday 00:00:00' '+%s'000)
today=$(date -d 'today 00:00:00' '+%s'000)
query1="{\"transactionDate\":{\$gte: new Date(${yesterday}),\$lte: new Date(${today})}}"
echo $yesterday
echo $today
mongoexport -d databasename-c collectionname --host yourip --port 27017 -p password -u username-q "${query1}" --type=csv --fields=transactionDate,amount > test5.csv
I've read the documentation (sqlcmd Utility), but I can't get sqlcmd's -v parameter to work as expected.
Assuming this SQL script (echo.sql):
:setvar THE_PATH C:\Users\Craig\Desktop
PRINT 'THE_PATH: $(THE_PATH)'
:setvar THE_TOP 10
PRINT 'THE_TOP: $(THE_TOP)'
When run at the PowerShell prompt without the -v argument set:
PS> sqlcmd -E -S 'server' -d 'database' -i '.\echo.sql'
THE_PATH: C:\Users\Craig\Desktop
THE_TOP: 10
Setting the numeric variable (THE_TOP) are ignored:
PS> sqlcmd -E -S 'server' -d 'database' -i '.\echo.sql' -v THE_TOP=5
PS> sqlcmd -E -S 'server' -d 'database' -i '.\echo.sql'
THE_PATH: C:\Users\Craig\Desktop
THE_TOP: 10
If I eliminate the default value for THE_TOP in echo.sql, it reinforced the assertion that the parameter is being ignored:
:setvar THE_TOP
PRINT 'THE_TOP: $(THE_TOP)'
PS> sqlcmd -E -S 'server' -d 'database' -i '.\echo.sql' -v THE_TOP=5
THE_PATH: C:\Users\Craig\Desktop
THE_TOP: $(THE_TOP)
If I attempt to set the THE_PATH parameter, I get:
PS> sqlcmd -E -S 'server' -d 'database' -i '.\echo.sql' -v THE_PATH="C:\path"
Sqlcmd: ':\path': Invalid argument. Enter '-?' for help.
What is the correct -v syntax?
OK, this is retarded.
If :setvar is used in the script:
:setvar THE_TOP
PRINT 'THE_TOP: $(THE_TOP)'
then you attempt to set it at the PowerShell prompt, you'll get an error:
PS> sqlcmd -E -S server -d database -i .\echo.sql -v THE_TOP=5
'THE_TOP' scripting variable not defined.
However, if you DO NOT set it in the script:
-- variable disabled
-- :setvar THE_PATH
PRINT 'THE_TOP: $(THE_TOP)'
then you attempt to set it at the PowerShell prompt, then it will work as (not really) expected:
PS> sqlcmd -E -S server -d database -i .\echo.sql -v THE_TOP=5
THE_TOP: 5
** edit **
To supply a dynamically-generated path as a parameter to a script file (extract.sql):
:out $(THE_PATH)\extract.csv
SELECT *
FROM the_table
WHERE the_key = $(THE_ID)
...
Execute in PowerShell session:
PS> $cd = Get-Location
PS> sqlcmd -E -S 'server' -d 'database' -i '.\extract.sql' -v THE_ID=5 THE_PATH=`"$cd\build`"