How can I skip errors and continue running Script? - applescript

I would like to know if it is possible to ignore a shell script command
and continue running the rest of the code, for example if the following
command return me nothing in the terminal and I continue to the next command.
EDIT:
I tried: 2>/dev/null
try
do shell script "kextstat|grep -y appleintel >/tmp/Intel.txt" with administrator privileges
on error
display alert "blabla..."
end try
end showIntel:```

Related

Run bash script loop in background which will write result of jar command to file

I'm novice to running bash script. (you can suggest me, if title I've given is incorrect.)
I want to run a jar file using bash script in loop. Then it should write the output of jar command into some file.
Bash file datagenerate.sh
#!/bin/bash
echo Total iterations are 500
for i in {1..500}
do
the_output="$(java -jar data-generator.jar 10 1 mockData.csv data_200GB.csv)"
echo $the_output
echo Iteration $i processed
done
no_of_lines="$(wc -l data_200GB.csv)"
echo "${no_of_lines}"
I'm running above script using command nohup sh datagenerate.sh > datagenerate.log &. As I want to run this script in background, so that even I log out from ssh it should keep running & output should go into datagenerate.log.
But when I ran above command and hit enter or close the terminal it ends the process. Only Total iterations are 500 is getting logged into output file.
Let me know what I'm missing. I followed following two links to create above shell script: link-1 & link2.
nohup sh datagenerate.sh > datagenerate.log &
nohup should work this way without using screen program, but depending on your distro your sh shell might be linked to dash.
Just make your script executable:
chmod +x datagenerate.sh
and run your command like this:
nohup ./datagenerate.sh > datagenerate.log &
You should check this out:
https://linux.die.net/man/1/screen
With this programm you can close your shell while a command or script is still running. They will not be aborted and you can pick the session up again later.

Exit from Shell script without executing anything

I have a shell script installed to run every day.
The script consists of some rm (delete) commands and SCP commands for file transfer. The script is failing due to some errors in production. I want the job to return exit code as 0 without executing anything, so I wrote
exit 0;
at the beginning of the shell script so that as soon as the script executes, it will exit with out any commands after that exit 0; but still the script is failing.
I cannot edit the whole contents inside the file nor delete the script or contents inside the script.
Please suggest whether I am using the right syntax for exit command or how to make the script to exit with return code 0 as soon as it starts executing.
The ';' is unnecessary. You can exit like this:
exit
exit 1
This is a description about 'Exit and Exit Status'.

Commands in sourced file are not found when executing bash script

My script first sources an API file, the executes a few commands from the file. When the script is executed from the command line, I get "command not found" errors for each of the commands. Here's the script:
#!/bin/bash
## include API file
source /cygdrive/c/path/to/unifi_sh_api
## login
unifi_login
## authorize a client for 30 minutes, limit down/up speed to 2048/1024kbps, quota is 500MB
unifi_authorize_guest "x2:ff:ff:ff:ff:ff" 30 up=1024 down=2048 bytes=500
unifi_logout
This returns "command not found" for the 3 unifi_* commands. There are no other errors.
This is on a Windows server and you can see I'm using Cygwin, so maybe that's part of the problem?
Here's what my sourced file looks like, in case the issue is there: https://dl.ubnt.com/unifi/4.7.6/unifi_sh_api
Any suggestions?
UPDATE:
Definitely using bash.
I did try . instead of source before posting my question here.
Here's the command I'm running in a cmd.exe window:
> C:\cygwin\bin\bash.exe -c '/cygdrive/c/path/to/myscript.sh'

Run a bash script via another bash script to delete a file is not working properly

I have a bash script start.sh which calls another run.sh, which takes me to another prompt where I have to delete a file file.txt and then exit out of that prompt.
When I call run.sh from inside start.sh, I see the prompt and I believe that it deletes the file.txt but the inner/new prompt waits for me to exit out of it while the script is running - meaning it needs intervention to proceed. How do I avoid it in bash?
In Python I can use Popen and get it going but not sure about bash.
EDIT: I would rather like to know what command to provide to exit out of the shell (generated from running run.sh") so I can go back to the prompt where "start.sh" was started.
Etan: To answer your question
VirtualBox:~/Desktop/ > ./start
company#4d6z74d:~$ ->this is the new shell
company#4d6z74d:~$ logout ---> I did a "Control D here" so the script could continue.
Relevant part of start.sh which:
/../../../../run.sh (this is the one that takes us to the new $ prompt)
echo "Delete file.txt "
rm -f abc/def/file.txt
You can run run.sh in the background using &. In start.sh, you would invoke the script via /path/run.sh &. Now, start.sh will exit without waiting for run.sh to finish (which is running in the background).

Executing a command after the first command executed

I just recently installed beep on Ubuntu and finally managed to get it to work.
So I was able to hear the beeping sound after executing:
beep
Everything worked well, however, I was just wondering if it's possible to execute "beep" everytime I execute a command. Say for example:
cat /etc/passwd && beep
After reading /etc/passwd, it will be executing a beeping sound. I'd like to know if there's a way to execute beep after every command without having me to use "&& beep" always.
A clearer example:
ls && beep
ls -la && beep
cat /etc/passwd && beep
Notice the constant command "beep" followed by "&&" after every initial command.
You can set PROMPT_COMMAND=beep (try it first, then add to your ~/.bashrc if it doesn't drive you crazy). This will execute beep just before it displays the command prompt.
You could try altering your prompt:
PS1="$PS1"'\007'

Resources