I am trying to run a filewatcher.sh script in background. It further invokes a java code through a jar file.
Whenever I run the command("nohup sh filewatcher.sh") through terminal, everything is ok. I have to hit enter two times so the output file is appended to nohup.out. But whenever I try to run the equivalent command("nohup filewatcher.sh >> nohup.out < /dev/null &") from a shell script automate.sh, I get following permission error.
error-log. Click to see snippet.
Could this an issue of permission for the automate.sh?
I have crossed check to see this script is having same permissions and ownership as the user when I log in and enter the nohup command from command line.
I also checked the ownership of the folders where the files are getting moved but everything is having same permissions and ownership.
Related
That is:
hashanp#DESKTOP-9E00J4S: ~/cats-cakes$ git add .
error: open("img/cake.jpg"): Permission denied
error: unable to index file img/cake.jpg
fatal: adding files failed
Trying to add image in Git add but keep getting the following message? I tried restarting/reloading git and closing VS Code but nothing worked.
That looks like a git bash session on Windows, or a WSL session.
If you can not easily identify the process which keeps an handle to that file, preventing another program (like git) to access it, I would:
reboot
restart my git bash or WSL2 session
try to add img/cake.jpg before opening any IDE.
Since it is an Ubuntu session, I would also try, for tesdting:
sudo chmod -R 755 img
That way, the folder img will be accessible.
I'm trying to basically run the following .bat file as a scheduled task, while also logging errors in a .txt file:
In the 'program/script' box, I just have cmd. Then in the add arguments box I have:
/k ""T:\Some_folder\mybatchfile.bat" >>"T:\somelog.txt" 2>&1"
This had been working just fine originally before I tried to add the log function and calling cmd explicitly as seen in several posts, but I'd really like to add this function. I'm using /k for now so that I can watch the cmd window as things happen, but plan to replace it with /c so it closes when its done.
I tried many permutations of where my quotation marks are but am not having a lot of luck. I'm also intentionally using >> vs > in order to append the log, not overwrite it.
The contents of the .bat file are basically:
"C:\RDirectory\R.exe" CMD BATCH "T:\Some_folder1\Preworkforbatch.R"
copy T:\Some_folder2\some_data.csv "C:\Users\ABC1\Another_folder"
copy T:\Some_folder3\some_more_data*.csv "C:\Users\ABC1\Another_folder"
I'm wondering if part of it is that T is a network folder that is mapped? Thanks for your help.
edit:
Here is more info on the task:
"T:\Some_folder\mybatchfile.bat" >> "T:\somelog.txt" 2>&1
When redirecting the output of a batch file to a log file you will not see as much output in the cmd window. You have to repeatedly open, close, open the log file to see your progress. Use the title command in your batch to display progress info in the cmd window.
title This is %~F0. The time is %time%. The date is %date%. SLEEP 3600 FOR :RECORDRADIO
Ok this ended up working for me, by editing the batch file itself, and just running the batch file (not cmd explicitly) in the task scheduler:
mybatchfile.bat:
#echo on
"C:\RDirectory\R.exe" CMD BATCH "T:\Some_folder1\Preworkforbatch.R" >> "C:\Users\ABC1\Logfolder\mylog.txt" 2>&1
copy T:\Some_folder2\some_data.csv "C:\Users\ABC1\Another_folder" >> "C:\Users\ABC1\Logfolder\mylog.txt" 2>&1
copy T:\Some_folder3\some_more_data*.csv "C:\Users\ABC1\Another_folder" >> "C:\Users\ABC1\Logfolder\mylog.txt" 2>&1
Writing the log file to the network was causing errors. Writing to the local computer solved this issue. Not using double quotes also was key, instead just quotes around the file/path. This setup gives me an output for each line, so for every line 2>71 shows up, I get an output if there's an error or a completion message.
This is what the task scheduler looks like:
I am trying to use PS1 to customise my command prompt in mac, but the changes are not saved, when I try to re-open the terminal.
I have edited the .bashrc file, and the changes are effective only for that session. If I close and re-open the terminal, all saved changes are lost.
Below is the .bashrc file that i have edited.
export PS1="\u#\h \d \# \w >"
export PATH="/Users/avbanerj/test_script1:$PATH"
Could you please tell me what shall I add in my .bashrc or .profile so that changes are reflected everytime I open the terminal?
This is from info bash.
-Erik
6.2 Bash Startup Files
======================
This section describes how Bash executes its startup files. If any of
the files exist but cannot be read, Bash reports an error. Tildes are
expanded in filenames as described above under Tilde Expansion (*note
Tilde Expansion::).
Interactive shells are described in *note Interactive Shells::.
Invoked as an interactive login shell, or with '--login'
........................................................
When Bash is invoked as an interactive login shell, or as a
non-interactive shell with the '--login' option, it first reads and
executes commands from the file '/etc/profile', if that file exists.
After reading that file, it looks for '~/.bash_profile',
'~/.bash_login', and '~/.profile', in that order, and reads and executes
commands from the first one that exists and is readable. The
'--noprofile' option may be used when the shell is started to inhibit
this behavior.
When an interactive login shell exits, or a non-interactive login
shell executes the 'exit' builtin command, Bash reads and executes
commands from the file '~/.bash_logout', if it exists.
Invoked as an interactive non-login shell
.........................................
When an interactive shell that is not a login shell is started, Bash
reads and executes commands from '~/.bashrc', if that file exists. This
may be inhibited by using the '--norc' option. The '--rcfile FILE'
option will force Bash to read and execute commands from FILE instead of
'~/.bashrc'.
So, typically, your '~/.bash_profile' contains the line
if [ -f ~/.bashrc ]; then . ~/.bashrc; fi
after (or before) any login-specific initializations.
I am running an SFTP batch to get a series of files from one unix server to another. I have a shell script that builds the batch files like:
cd path
get filename
cd path
get filename
and more.
Is there a way within SFTP to NOT run a get command if the preceding cd command fails, but keep running the rest of the batch?
To be clear, I do NOT want to terminate the whole SFTP batch, just the one get command if it's related cd command does not work.
After each cd check error code, if it is 0, everything is fine. If not, some error occured in last command...
Like:
cd directory
if [!$?]
then
get something
fi
Thanks in advance:
I'm attempting to use Notepad++ to log-in to a UNIX system. I am using the NPPExec console to do this, and the login process works... kind of. I use NPPExec to execute this script, named "sasunix.sh":
"C:\userblah\username\Desktop\plink.exe" -load "SUN4" -l myloginname -pw mypassword
As you can see I am using Putty's command line program "plink.exe" to send the command; "SUN4" is the session profile I am using. The problem is, the next screen logs me in (successfully), but proceeds to ask me for my password an additional time (which is part of the login procedure), followed by a request for my my terminal emulation setting (for me, this is 'xterm').
THE QUESTION: What additional lines would I add to my script to execute this sequence of inputs on the UNIX system (i.e. typing them in individually and pressing "ENTER" each time):
1.) thepassword 2.) xterm 3.) sas -nodms -nonews
I think this boils down to a misunderstanding of how commands are passed between NotePad++ and the NPPExec console window. At any point, if I press "F6", a prompt pops up, saying "WARNING: Console process still running...". This messagebox prompt allows me to type in a line which is then sent to the console... but how do I put a series of these inputs into the script?
You prob have this solved by now,
but i have done the following
a windows batch script that creates a file with unix commands, based on the a directory path
#ECHO OFF
:: store input variable
set str=%1
:: remove C:\ or Z:\ etc
set str=%str:~3%
:: replace \ with /
set str=%str:\=/%
:: append cd command
set str1=cd
set str=%str1% %str%
echo.%str%
:: make
echo make clean
echo make all
Install the NppExec plugin to Notepad++
Place the *.bat scripts and plink.exe in the Notepad++ program directory
Create the NppExec commands
// This line calls the bat file and creates a file tempcmd.sh with unix commands in it
"$(NPP_DIRECTORY)\unix_make_all.bat" $(CURRENT_DIRECTORY) >tempcmd.sh`
// This line connects to a remote machine and runs all the commands stored in tempcmd.sh
"$(NPP_DIRECTORY)\plink.exe" -ssh -2 -l username -pw password 192.168.000.000 -m "$(NPP_DIRECTORY)\tempcmd.sh"
Using the NppExec options i save the above commands and place a shortcut in the macros menu