I need to execute a Babun script with Windows Scheduler on Windows Server 2003, the problem is: How can I execute a script in Babun shell from a .bat or similar?
The script is a really simple one line rsync command.
Here is the Babun reference.
first copy .babunrc to .babun_scheduler_rc and add one line export PATH="/usr/bin:$PATH"
The location of .babunrc is: C:\Users\user\.babun\cygwin\home\user you can edit it from babun too.
next create the script.bat:
#echo off
setlocal enableextensions enabledelayedexpansion
set SCRIPT_PATH=%~dp0
set SCRIPT_PATH=%SCRIPT_PATH:\=/%
set BABUN_HOME=%SCRIPT_PATH%
set CYGWIN_HOME=%BABUN_HOME%\cygwin
set BASH=%CYGWIN_HOME%\bin\bash.exe
"%BASH%" -c "source ~/.babun_scheduler_rc && rsync -Crav /cygdrive/c/Path/To/Copy user#remote:/tmp/path/to/copy"
and now you can add it to the scheduler.
Related
I have this bash script but it wont set the paths and I am not sure why. I can set the paths manually by typing each command.
#!/bin/bash
parent_path=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P )
export PATH=$PATH:$parent_path/arm-2013.11/bin;
export ARMGCC_INSTALL_PATH=$parent_path/arm-2013.11;
export ARMGCC_VERSION=4.8.1;
You should use the source/. built-in to run this script.
Running vs Sourcing the script:
Running the script opens a new shell. All changes to the environment will be lost after the program executes.
Sourcing the script runs the script in the current shell. Think of .bashrc - it is being sourced, therefore allowing changes to the environment.
So you should run:
source /path/to/script.sh
Speaking of .bashrc, if you find the process of sourcing the script tedious, you should add this to your .bashrc:
alias aliasnamehere="source /path/to/script.sh"
and change the alias to the one you prefer.
I'm new to linux scripting. I want to copy file from remote server to current server(executing or client server),required cert & key files are already installed on my server(client server). below commands work when I execute it individually in sequence but, after Integrating into a .sh script it doesnt!
--My Script--
lftp -u username,xxx -p 2121 remoteServer.net;
set ssl:cert-file /abc/def/etc/User_T.p12;
set ssl:key-file abc/def/etc/User_T.p12.pwd;
lftp -e 'set net:timeout 10; get /app/home/atm/feed.txt -o /com/data/';
man lftp:
-f script_file
Execute commands in the file and exit. This option must be used
alone without other arguments (except --norc).
-c commands
Execute the given commands and exit. Commands can be separated
with a semicolon, `&&' or `||'. Remember to quote the commands
argument properly in the shell. This option must be used alone
without other arguments (except --norc).
Use "here document" feature of the shell:
lftp <<EOF
set...
open...
get...
EOF
Thanks lav for your suggestion, I found that my script was not executing second line so added continuation like
<< SCRIPT
& ended script with SCRIPT
removed all semi colon... Its working
I have a batch file and it has below command(.bat file) to execute my application. I need to move the same application to Linux environment and need to write .sh file to execute the same application. I don't have any idea of the shell scripting. Please can some one give idea to convert this to .sh file?
SET currentDir=%CD%
CD %~dp0
SET CLASSPATH=./lib/*;
java -Dlogback.configurationFile=./com/logback.xml -cp "%CLASSPATH%";"App.jar" com.test.main.MainClient
SET ERROR_LEVEL=%ERRORLEVEL%
CD %currentDir%
EXIT /B %ERROR_LEVEL%
Since it dosn't appear to be very complex, conversion shouldn't be too dificult. Have look here for a comparison of batch and bash syntax.
You can leave your java-command almost as it is, just change the way you call CLASSPATH. And keep in mind that bash is case-sensitive.
I created the following script, by my _vimrc is not loaded...
gvim opens but no vimrc
NOTE: If I put the _vimrc in %USERPROFILE% it is loaded but this is not what I want
#echo off
set GVIMPATH="C:\Program Files\Vim\vim73"
set PATH=%PATH%;%GVIMPATH%
set MYVIMRC=U:\Work\vim\_vimrc
set MYGVIMRC=U:\Work\vim\_vimrc
set VIMHOME=U:\Work\vim
start gvim.exe
What I mentioned here was wrong, MYVIMRC apparently is read-only; one cannot use it to override the .vimrc location. In a wrapper script, better pass the location via the -u command-line argument:
#echo off
set GVIMPATH="C:\Program Files\Vim\vim73"
set PATH=%PATH%;%GVIMPATH%
set VIMHOME=U:\Work\vim
start gvim.exe -u U:\Work\vim\_vimrc -U U:\Work\vim\_gvimrc
You can pass the -u option when you execute vim to load a custom vimrc file from wherever you want, like: vim -u C:\Windows\whatever\vimrc_files\statquant_custom_vimrc, for example.
You can take a look on this SuperUser question, maybe it can help you.
I am creating a batch file to siliently install nodejs on a Windows XP machine.
I am trying to automate the installation of node module dependencies (npm install).
I would normally issue npm install from the cmd prompt in the target installation directory.
I am struggling to automate the interaction with the command prompt from a batch file.
The following line in my batch script seems to make it possible for me to pipe a text file of commands to cmd:
for /F "usebackq delims=," %%i in ("c:\foo\source\npm_install.txt") do echo %%i | "c:\windows\system32\cmd.exe"
The batch file is located in c:\foo\source. I need to issue 'npm install' from c:\foo\bin.
If my npm_install.txt file is such:
cd /d c:\foo\bin,
npm install
The cmd prompt will perform the first command changing the directory from c:\ to c:\foo\bin.
It will then perform the second command but starting from c:\ again. The previous command to change directories doesn't persist. It seems every command in the text file will be issued from c:\ .
I next tried to issue both commands from a combined statment:
cd /d c:\foo\bin && npm install
It seems this approach will allow me to overcome the prior path problem but I then have an issue with the space between npm and install.
The cmd prompt performs c:\foo\bin>npm and causes npm to trip on the space.
I have tried enclosing the command without success: 'npm install', "npm install", (npm install).
Can anyone tell me what I am doing wrong?
Thanks.
The problem is that your batch-processing script is creating a new subshell to handle each line in your install file. Thus your cd command is executed in a subshell, changing its working directory, but then the subshell exits and you're back in the parent shell's working directory.
Can your main script simply call your install script (whose extension would have to be changed to ".bat")? call lets you run another batch file in the same shell and then continue running your original script.
You do not need this:
do echo %%i | "c:\windows\system32\cmd.exe". Simply put your commands in a block.
do (
command
command
...
)
With your previous statement, you start new cmd interpreter, ask it to execute a command for you and exit - that's why you loose effect of that cd.
If you do not specify tokens in for loop, only 1st is read. Plus, all tokens must be on same line (I'm not sure if what you show is not a byproduct of formatting)
Use "delims=" to read full line.
Do not mix commands with arguments if you do not have to: put only directories in your file:
c:\foo\bin
c:\bar\bin
so finally it becomes (I replaced cd with pushd/popd so you'll end up in the same dir you started from):
for /F "usebackq delims=" %%i in ("c:\foo\source\npm_install.txt") do (
pushd %%i
npm install
popd
)
Edit: if npm install is batch itself, you will need to use call, as ebohlman noted
NOTE: These three examples do not require you to put CALL in front of any batch files, that functionality is built-into each.
The smallest and simplest, it just executes the commands with their arguments:
#echo off
for /f "tokens=*" %%x in (c:\foo\source\npm_install.txt) do (
call %%x
)
To mimic a person typing the commands at the keyboard:
#echo off
for /f "tokens=*" %%x in (c:\foo\source\npm_install.txt) do (
setlocal enabledelayedexpansion
:: Mimic commandline
call set "cmd=%%cd%%"
echo !cmd!^>%%x
endlocal
:: Preform command
call %%x
echo.
)
To end up in the same directory you started in, no matter where the script ends:
#echo off
setlocal enabledelayedexpansion
for /f "tokens=*" %%x in (c:\foo\source\npm_install.txt) do (
:: Mimic commandline
call set "cmd=%%cd%%"
echo !cmd!^>%%x
:: Preform command
call %%x
echo.
)
endlocal