I am trying to write a batch file that checks if your computer name is a certain name, and then if it matches the exe file will run.
#echo off
echo adidas shoe cop bot console...
echo by sam
pause
echo checking for computer name...
If %computername%=="DESKTOP-HQPDA76"
then echo %computername% found
echo user confirmed
echo starting file
pause
start /B "" "C:\Users\Sam Marriott\Desktop\Adidas Shoe Cop Bot\Package\Adidas Shoe Cop Bot\bin\Debug\Adidas Shoe Cop Bot.exe"
pause
Else NOT %computername%=="DESKTOP-HQPDA76"
then echo user access denied
pause
I am getting some error about (something) was not expected here, or syntax error, but I can't really read it because the command prompt closes too quickly. Any help?
Your syntax for the IF statement is wrong. Try this:
#echo off
echo adidas shoe cop bot console...
echo by sam
pause
echo checking for computer name...
if "%computername%"=="DESKTOP-HQPDA76" (
echo %computername% found
echo user confirmed
echo starting file
pause
start /B "" "C:\Users\Sam Marriott\Desktop\Adidas Shoe Cop Bot\Package\Adidas Shoe Cop Bot\bin\Debug\Adidas Shoe Cop Bot.exe"
pause
) else (
echo user access denied
pause
)
Related
We have an android device and as part of testing I need to excute a console test application on the target device. If the test application detects an error it returns -1.
I can use adb shell to run the test applications remotely on the target but I can't find a way of getting back the return code. I need this so I that I can build this into an automated test suite.
I could try grepping the console output for some failure text but that is a bit grubby. Does anyone know of a more elegant solution?
This is a workaround to get the exit code:
adb shell '{your command here} > /dev/null 2>&1; echo $?'
This is a wrapper around adb in Ruby:
def adb(opt)
input = "#{adb_command} #{opt[:command]} #{opt[:params]}"
puts "Executing #{input}...\n"
output = nil
exit_code = 0
def wait_for(secs)
if secs
begin
Timeout::timeout(secs) { yield }
rescue
print 'execution expired'
end
else
yield
end
end
wait_for(opt[:timeout]) do
case opt[:command]
when :install, :push, :uninstall
output, exit_code = `#{input}`, $?.to_i
when :shell
input = "#{adb_command} shell \"#{opt[:params]}; echo \\$?\""
output = `#{input}`.split("\n")
exit_code = output.pop.to_i
output = output.join("\n")
else
raise 'Error: param command to adb not defined!'
end
end
return if opt[:ignore_fail] and output =~ /#{opt[:ignore_fail]}/
raise output unless exit_code == 0
end
You could use Facebook's fb-adb, a "A better shell for Android devices" which "propagates program exit status instead of always exiting with status 0".
I have a file (text or csv) that I generate that has a list of part numbers. I need to take this list, and download some spec sheets for these parts automatically and then print. Once on the website, I need to input the part number, then print the results. What's the best way to do this?
Okay everyone, here's what I was doing before, but it would take over an hour to process on a progress 4gl (version 9.1) database into a QAD environment v8.6e on a Unix Red-Hat server:
FNAME=`date +%y%m%d%H%M%S`
echo requiredmcpartno=$1 | lynx -accept_all_cookies -nolist -dump -post_data 75.144.##.###/specdata/specdata.asp 2>&1 | tee $FNAME | lp -d$2 >>/apps/proedi/####/ftp/log/brownart.log
grep "Unit of Issue" $FNAME | cut --delimiter=: --fields=2 | awk '{print $1}'
grep -q "PACKAGING SPEC IS OBSOLETE FOR THIS PART NUMBER" "$FNAME"
if [ $? -eq 0 ]; then
echo 0
echo nopic
exit
fi
cd /apps/proedi/####/ftp/ftpscripts
rm -fr 184.168.##.###/ 75.144.##.###/ www.google-analytics.com/ 2>&1 >>/apps/proedi/####/ftp/log/brownart.log
wget -p -m -k -K -E -H --cookies=on --post-data="requiredmcpartno=$1" 75.144.##.###/specdata/specdata.asp >/dev/null 2>&1
/apps/proedi/####/ftp/ftpscripts/printspec.sh $1 $2 >>/tmp/printspec.log 2>&1
cat /apps/proedi/####/ftp/ftpscripts/"$1".pt
rm -f /apps/proedi/####/ftp/ftpscripts/"$1".pt
>>/apps/proedi/####/ftp/log/brownart.log
rm $FNAME 2>&1 >>/apps/proedi/ford/ftp/log/brownart.log
Then printspec.sh script:
file=184.168.70.174/partandpackagingphotos/PhotoDetailsSpecdata.aspx\?p\=$1.html
if [ ! -f "$file" ]; then
echo nopic >/apps/proedi/ford/ftp/ftpscripts/"$1".pt
exit
fi
grep -q "No Pictures Available for this Part Number" "$file"
if [ $? -eq 0 ]; then
echo nopic >/apps/proedi/ford/ftp/ftpscripts/"$1".pt
exit
fi
html2ps -i .7 184.168.70.174/partandpackagingphotos/PhotoDetailsSpecdata.aspx\?p\=$1.html | lp d$2 -s
echo picfnd >/apps/proedi/ford/ftp/ftpscripts/"$1".pt
The wget command takes way to long to process in Unix. Our customer may send us a conveyance file with 150-200 parts 8-9 times a day, and we need to download all of the pictures associated with each part every time we receive parts.
I was thinking of just making a flat file(text or csv), then have the user run a batch file on their windows computer to connect to the unix server, and download the file to their computer. After this, then have either the same batch job, or an excel template or something on the windows side download the pictures and print the spec sheets to their default printer.
Sorry for not posting all of this initially.
The first thing that I would try is to break the process into two or more independent pieces and run them in parallel. The scripts above appear to take a part number as a parameter. I would guess that whatever is feeding them the part number is working from a list (the "conveyance file"?) That list would be the obvious place to make the split.
If you do it in such a way that the number of concurrent processes is configurable it should be simple to find the "sweet spot". Supposing that the list of parts to be downloaded is in a table called "part" with fields "needsDownload" and "partNum". For the sake of simplicity we will assume that partNum is an integer and that the actual part numbers needing download are randomly distributed. If you are driving this process with Progress 4GL code you might write a control program something like this:
/* control.p
*
* to run two "threads":
*
* _progres -b dbName -p control.p -param "1,2" > control.1.log 2>&1 & # 1 of 2
* _progres -b dbName -p control.p -param "2,2" > control.2.log 2>&1 & # 2 of 2
*
*
*/
define variable myThread as integer no-undo.
define variable numThreads as integer no-undo.
myThread = integer( entry( 1, session:parameter )) - 1. /* this just allows the "1 of 2" stuff to be more "human sensible" */
numThreads = integer( entry( 2, session:parameter )).
for each part exclusive-lock where needsDownload = true and (( partNum modulo numThreads ) = myThread ):
os-command value( "getpart.sh " + string( partNum )).
needsDownload = false.
end.
Of course the problem might be that the external system is too slow. No amount of programming on your end will fix that.
I have been trying to create a batch file to backup MySQL database. All worked fine but the backup is just empty. I don't know where have gone wrong. Here is my code
set year=%DATE:~10,4%
set day=%DATE:~7,2%
set mnt=%DATE:~4,2%
set hr=%TIME:~0,2%
set min=%TIME:~3,2%
IF %day% LSS 10 SET day=0%day:~1,1%
IF %mnt% LSS 10 SET mnt=0%mnt:~1,1%
IF %hr% LSS 10 SET hr=0%hr:~1,1%
IF %min% LSS 10 SET min=0%min:~1,1%
set backuptime=%year%-%day%-%mnt%-%hr%-%min%
echo %backuptime%
set dbuser=root
set dbpass=vsplabs
set mysqldumpexe="C:\Program Files\MySQL\MySQL Server 5.6\bin\mysqldump.exe"
set backupfldr="C:\Users\sowmya\Desktop\Mysqlbackups"
set datafldr="C:\ProgramData\MySQL\MySQL Server 5.6\data"
set zipper="c:\MySQLBackups\zip\7za.exe"
pushd %datafldr%
echo "Pass each name to mysqldump.exe and output an individual .sql file for each"
#echo off
FOR /D %%F IN (*) DO (
IF NOT [%%F]==[performance_schema] (
SET %%F=!%%F:#002d=-!
%mysqldumpexe% --user=%dbuser% --password=%dbpass% --databases --routines --log-error=%errorLogPath% %%F > "%backupfldr%%%F.%backuptime%.sql"
) ELSE (
echo Skipping DB backup for performance_schema
)
)
echo "Zipping all files ending in .sql in the folder"
%zipper% a -tzip "%backupfldr%FullBackup.%backuptime%.zip" "%backupfldr%*.sql
echo "done"
popd
And another issue I just wanted only one database its being retrieving all the databases from database..How to modify that and And i have been getting an extra database named as "mysql"
This can be run directly in cmd (I wrapped the line but it should not be wrapped):
You should give the root access.
mysql.exe -uroot -p1234 -s -N -e "SHOW DATABASES" |
for /F "usebackq" %D in (`findstr /V "information_schema performance_schema"`)
do mysqldump %D -uroot -p1234 > S:\Backup\MySQL\%D.sql
In a batch file you will need to escape % with an additional %, that is use %%D.
You see i use CoreTemp program to monitor CPU heat, this program allows you to run a script or a program when the CPU temp reaches a specified value..
What i want is that when the CPU temp reaches a certain value, the process that has the most CPU usage is to be closed!!
In other words, I need a Script/program that automatically scans the processes and force close the process that has the highest CPU usage..
Thanks!
Try this :
Check the prog with the higher Memory Use :
#echo off
setlocal EnableDelayedExpansion
for /f "skip=4 tokens=1-5 delims= " %%a in ('tasklist') do (
set $Size=00000000%%e
set $Size=!$size:.=!
set #!$size:~-10!=%%a
)
for /f "tokens=2 delims==" %%a in ('set #') do (set $Bigger=%%a)
echo taskkill /IM !$Bigger!
Check the process with the higher CPU use :
#echo off
setlocal EnableDelayedExpansion
for /f "skip=2 tokens=1-2 delims= " %%a in ('"wmic path Win32_PerfFormattedData_PerfProc_Process get Name,PercentProcessorTime"') do (
if "%%a"=="_Total" goto:next
set #%%b=%%a
)
:next
for /f "tokens=1-2 delims==" %%a in ('set #') do (
set $Bigger=%%b
set $Value=%%a
)
if "!$Value!"=="#0" goto:nothing
echo taskkill /IM !$Bigger!.exe [!$Value:#=!%%]
goto:eof
:nothing
Echo CPU IS INACTIVE
If the output is OK for you remove the ECHO on the last line
You can ameliorate the script. In case you have two processus with the same name you have to work with th PID of the process in place of the name. Because the programm will return program#1, program#2, etc.. That's just the base script.
And Like #09stephenb commented you have to go carrefully with such a script....
I started working on this for you but I have to leave. It's mostly complete so I'm just gonna give you what I have so far and let you take it from there.
#echo off
setlocal
set proc=Win32_PerfFormattedData_PerfProc_Process
set "wmi=wmic path %proc% get Name^,PercentProcessorTime"
for /f "skip=1 tokens=*" %%a in ('"%wmi%"^|findstr /i /v /g:Excludes.txt') do (
for /f "tokens=2 delims= " %%b in ( "%%a" ) do if %%b NEQ 0 echo %%a
)
Create a file called Excludes.txt and make sure it's in the same dir of your script.
"System Idle Process"
Idle
explorer.exe
taskmgr.exe
lsass.exe
csrss.exe
smss.exe
winlogon.exe
svchost.exe
services.exe
Core Temp
_Total
I need a script, prefferably a windows batch or C# to do as following:
Show a prompt that first ask for the source folder,
then it should ask for the destination folder. At last, it shall ask how many files it should copy to the destination, from the source.
// We talk about aprox 100.000 files and they can be moved in random order.
After the process has been run, the program shall make a break of 10 minutes, then loop the process it was told to earlier, by previous answers to the prompt.
I've tried a little, but haven't found a solution. As far as i can see, XCOPY is unable to work around all these criterias.
Thanks in advance,
Mark
RoboCopy (the See also section might interest you as well) or
(more recent:) RichCopy (download)
You can use something like this:
string source = Console.ReadLine();
string destination = Console.ReadLine();
int numberOfFilesToCopy = int.Parse(Console.ReadLine());
DirectoryInfo di = new DirectoryInfo(source);
var files = di.GetFiles();
for(i=0;i < math.Max(files.Length, numberOfFilesToCopy);i++)
{
files[i].CopyTo(destination);
}
In C# using System.IO.File.Copy(sourceFileName,destFileName) followed by a System.IO.File.Delete(path) will do the "move" for you. You can create a simple console app that takes in the information you need and then does the work.
Have a look at the docs for System.IO.File for more info on File operations.
I'm not sure this fulfills all your requirements, but it may be useful to have a look at robocopy (robocopy /? in the command line).
Don't think I missed anything =D
#ECHO OFF
::User Prompts
SET /p source=Source Folder? Use format DRIVE:\PATH\ :
SET /p destination=Destination Folder? Use format DRIVE:\PATH\ :
SET /p count=How many files to copy? :
::Setup the Batch file to schedule
DIR /B "%source%">>"%userprofile%\batchtemp\source.BAT"
SET batchfile=%userprofile%\batchtemp\source.BAT
ECHO SETLOCAL ENABLEDELAYEDEXPANSION>>"%batchfile%"
ECHO FOR /F "USEBACKQ tokens=*" %%A IN ("%batchfile%") DO ( >>"%batchfile%"
ECHO COPY /Y "%%~fA" "%destination%\%%~nxA">>"%batchfile%"
ECHO SET /a count=!count!-1>>"%batchfile%"
ECHO IF %count% EQU 0 GOTO CLEANUP>>"%batchfile%"
ECHO )>>"%batchfile%"
ECHO :CLEANUP>>"%batchfile%"
ECHO ENDLOCAL>>"%batchfile%"
::Setup the scheduled task based on a future time in minutes.
REM Given that the job will run on the same day not overlapping a 24 hour day
FOR /F "tokens=1-3 delims=: " %%F IN ('time /t') DO (
SET hours=%%F
SET minutes=%%G
)
FOR /F "tokens=1-4 delims=/ " %%F IN ('date /t') DO (
SET day=%%F
SET thedate=%%G/%%H/%%I
)
SET /a minutes=%minutes%+10
IF %minutes% GRT 60 SET /a minutes=%minutes%-60 & SET /a hours=%hours%+1
SCHTASKS /Create /TR "%batchfile%" /ST %hours%:%minutes%:00 /MO ONCE /D %day% /SD "%thedate%" /ED "%thedate%" /TN "Copy Files"