Services, shell scripts and errors
Unix question here:
I am playing around with the new services feature of SL. Great stuff. Generally I am writing little one line scripts to do minor operations (like touch, for example). However, when there is an error in the script, the service craps out with an error dialog. I'd like to ignore the error & continue on. I've tried redirecting stderr to /dev/null, but it doesn't seem to work. Here is an example of a script that will fail the second time it is run over a set of files:
for i in *; do xattr -d com.apple.quarantine "$i"; done
Does anyone know of a way to get the service system to ignore any errors that the script may encounter?
the standard unix way works for me. I'm not sure what problems you guys are having.
<pre style="
font-family: Monaco, 'Courier New', Courier, monospace;
font-size: 10px;
margin: 0px;
padding: 5px;
border: 1px solid #000000;
width: 720px;
color: #000000;
background-color: #ADD8E6;
overflow: auto;"
title="this text can be pasted into the Script Editor">
for f in "$@"
do
xattr -d com.apple.quarantine "$f" >/dev/null 2>&1 &
done</pre>
Similar Messages
-
how to run 3 job(a,b,c) parallel in unix shells script and after will complete d will start and we have to handle the error also
032ee1bf-8007-4d76-930e-f77ec0dc7e54 wrote:
how to run 3 job(a,b,c) parallel in unix shells script and after will complete d will start and we have to handle the error also
Please don't overwhelm us with so many details!
Just off the top of my head ... as a general approach ... something like
nohup proca
nohup procb
nohup procc
while (some condition checking that all three procs are still running ... maybe a ps -ef |grep )
do
sleep 2
done
procd
But, we'd really need to know what it is you are really trying to accomplish, instead of your pre-conceived solution. -
Need help with shell scripting and Patching
Hello all,
I am a very new Oracle DBA and I just have an interview where i have been ask two questions that i have no idea of what it is
1/ What is shell scripting and how do you do shell scripting?
2/ What is Patching and how do you do patching?
Can some one help to have a very good understanding of these tow questions?
Thanks a lot1/ What is shell scripting and how do you do shell scripting?shell accept command from you (via keyboard) and execute them. But if you use command one by one (sequence of 'n' number of commands) , the you can store this sequence of command to text file and tell the shell to execute this text file instead of entering the commands. This is know as shell script.
Shell script defined as:
"Shell Script is series of command written in plain text file. Shell script is just like batch file in MS-DOS
for example:- for taking backup, health check and doing some task Operating system level or Oracle database level we can create shell script and schedule a cron job
2/ What is Patching and how do you do patching?for example ,in windows while using sometimes you might face an issue/error and it gives pop up error message would like to send/report this error to microsoft? microsoft will send you a fix for that. lot of fixes for errors/bugs are released as patches.( n number of patches with newer features are releases as new version)
likewise in oracle for resolving bugs we should have to apply patch.
patch is basically a fix for a bug/bugs. we need to use opatch utility to apply the paches.
hope, this helps you -
SAP XI: How To Write Shell Script And use it in File Adapter On XI Server
Hi,
I want to split file at sender side in XI using Shell Script and then after i want to do
Mapping.
Can anyone tell me what exactly it means "write a script in UNIX shell on XI SERVER"?
Regards,
Akshay.Hi,
You can execute a Unix script running in the XI server from the File communication channel. Ie. if you want to do something which was not part of XI adapter configuation , then you can make use of external unix script and you can execute those from the XI.
For this, write a unix script and place in the XI OS level provided that path is accessible from PI Channel.
E.g
So u can use this in either Sender Channel to modify the data before it reaches into the Integration Server or in Receiver channel it is generally used to transfer the files into different location via Secure FTP
SAP help: http://help.sap.com/saphelp_nw2004s/helpdata/en/bc/bb79d6061007419a081e58cbeaaf28/content.htm
Blog:/people/sameer.shadab/blog/2005/09/21/executing-unix-shell-script-using-operating-system-command-in-xi
XI can be in any OS.
Hope this helps,
Rgds,
Moorthy -
Passing params from SQL file to Shell Script and then from Shell to SQL Fil
Afternoon guys,
Have a fun question for all you gurus in shell scripting out there. I have a shell script that is calling 2
different SQL programs. My objective is to pass a variable called request_number from one sql program
to the shell script and then from the shell script back to another SQL program. I will explain why I
need this to happen.
Here is what the shell script looks like which calls sql programs student_load_a.sql and
student_load_b.sql. Student_load_a.sql basically creates the control file (.ctl) which is needed for the
SQL*Loader and then student_load_b.sql reads the table that was just loaded and does the main
processing. My main objective here is to be passing the request_number which is being generated
using an Oracle Sequence in student_load_a.sql and using this generated number in my main
processing in student_load_b.sql to select records from the table based on request_number.
Any ideas ?Any help or recommendations is welcome and appreciated.
*1. Shell Script*
# Accept system input parameters
p_user_id=$1
p_job_id=$2
# Create control files for sqlload
sqlplus.exe -s $p_user_id @$STUDENT_PATH/student_load_a.sql $p_job_id
exit_status=$?
# Do sqlloads
sdesqlldr.exe userid=$p_user_id control=student_load-$p_job_id.ctl \
log=student_load-$p_job_id.log \
bad=student_load-$p_job_id.bad
exit_status=$?
# Main processing
# sqlplus.exe -s $p_user_id @$STUDENT_PATH/student_load_b.sql $p_user_id $p_job_id $p_request_number
sqlplus.exe -s $p_user_id @$STUDENT_PATH/student_load_b.sql $p_user_id $p_job_id
exit_status=$?
exit 0*2. student_load_a.sql (Would like to pass back the Sequence Number back to shell script and then use in student_load_b.sql*
-- Accept system input parameters
define p_job_id = &1
spool student_load-$p_job_id.ctl
select
'append into table TMP_STUDENT_LOAD
FIELDS TERMINATED BY '','' optionally enclosed by ''"''
trailing nullcols
(request_number CONSTANT ' || '''' || request_number_seq.nextval || ''',
student_id)'
from dual
spool off;
exit 0;
{code}
*3. student_load_b.sql (This is a big file so I am only adding code that is relevant for the SQL)*
{code}
declare
v_request_number number(6);
v_student_id number(7);
cursor cur_student_load is
select student_id
from TMP_STUDENT_LOAD
where request_number = v_request_number
order by 1;
begin
v_user_id := '&1';
v_job_id := &2;
-- This is the variable I would like to be be passing from shell script to student_load_b.sql
-- v_request_number = '&3';
open cur_student_load;
fetch cur_student_load into v_student_id;
exit when cur_student_load%notfound;
.... more logic of if then else in here
close cur_student_load;
end;
{code}
Edited by: RDonASnowyDay on Jan 29, 2010 4:03 PMHow come you are mixing WinDoze script (*.exe) with Unix?
You are aware that you will be passing the password along with the user id to the second sql script?
I will assume Unix ksh:
# Accept system input parameters
p_user_id=$1
p_job_id=$2
# Create control files for sqlload
p_seqno=`sqlplus -s $p_user_id @$STUDENT_PATH/student_load_a.sql $p_job_id`
exit_status=$?
# Do sqlloads
sqlldr userid=$p_user_id control=student_load-$p_job_id.ctl \
log=student_load-$p_job_id.log \
bad=student_load-$p_job_id.bad
exit_status=$?
# Main processing
# sqlplus -s $p_user_id @$STUDENT_PATH/student_load_b.sql $p_user_id $p_job_id $p_request_number
sqlplus -s $p_user_id @$STUDENT_PATH/student_load_b.sql \
$p_user_id $p_job_id $p_seqno
exit_status=$?
exit 0And the first sql script would look like this:
-- student_load_a.sql
-- Accept system input parameters
set echo off pages 0 feed off lin 80 trims on ver off
def p_job_id = &1
col seqno NEW_VALUE seqno
select request_number_seq.nextval seqno from dual;
set term off
spool student_load-$p_job_id.ctl
select
'append into table TMP_STUDENT_LOAD
FIELDS TERMINATED BY '','' optionally enclosed by ''"''
trailing nullcols
(request_number CONSTANT ''&&seqno'',
student_id)'
from dual
spool off;
exit 0;
{code}
:p -
Shell Script gives error when run through cron job.
Hi,
The following shell script runs without any problem when executed manulally.
USED=$(df -h /arch | tail -1 | awk '{print $5}' | cut -d '%' -f 1)
if [ ${USED} -gt 90 ]
then
find /arch/AUBUAT/ -type f -mtime +0 | xargs rm
find /arch/AUBMIG/ -type f -mtime +0 | xargs rm
fi
But the same gives below error when called from a cron job:
/backup/arch_test.sh: syntax error at line 1: `USED=$' unexpected
We are running following version:
bash-3.00$ uname -a
SunOS uaeaubdbdr01.aub.af 5.10 Generic_141444-09 sun4u sparc SUNW,SPARC-Enterprise
Kindly assist.
Thanks
Edited by: user13362786 on Apr 20, 2011 4:36 AMHi,
When I used #!/usr/bin/sh now even the manul execution of the script fails with the same err:
bash-3.00$ ./arch_test.sh
./arch_test.sh: syntax error at line 2: `USED=$' unexpected
And when I used #!/usr/bin/ksh the manual execution runs fine but again when the script is run from cronjob it now give dirrect err:
/backup/arch_test.sh[2]: df: not found
/backup/arch_test.sh[2]: tail: not found
/backup/arch_test.sh[2]: cut: not found
/backup/arch_test.sh[2]: awk: not found
/backup/arch_test.sh[3]: test: argument expected -
ADC PHP enabling shell script throws errors
Hi, guys.
I recently tried to enable PHP on my MacBook Pro.
I speak some bash, but no AppleScript.
On the Apple Developer Center they write you a little script to enable PHP, which failed repeatedly before numerous edits by me. I eventually massaged the script to work, but I want to understand *why* the script didn't work.
The code they give is as follows (and you can find it here: http://developer.apple.com/mac/articles/internet/phpeasyway.html):
set admin_email to (do shell script "defaults read AddressBookMe ExistingEmailAddress")
user_www=$HOME/Sites
filename=php-test
user_index=${user_www}/${filename}.php
user_db=${user_www}/${filename}-db.sqlite3
# NOTE: Having a writeable database in your home directory can be a security risk!
conf=`apachectl -V | awk -F= '/SERVER_CONFIG/ {print \$2}'| sed 's/"//g'`
conf_old=$conf.$$
conf_new=/tmp/php_conf.new
touch $user_db
chmod a+r $user_index
chmod a+w $user_db
chmod a+w $user_www
echo "Enabling PHP in $conf ..."
sed '/#LoadModule php5_module/s/#LoadModule/LoadModule/' $conf | sed
"s^[email protected]^\$admin_email^" > $conf_new
echo "(Re)Starting Apache ..."
osascript <<EOF
do shell script "/bin/mv -f $conf $conf_old; /bin/mv $conf_new $conf;
/usr/sbin/apachectl restart" with administrator privileges
EOF
Here are where this code throws errors for me:
First:
set admin_email to (do shell script "defaults read AddressBookMe ExistingEmailAddress")
I don't even recognize the shell syntax that this would work in. It's sort of csh like. Is this AppleScript?
Anyway, OS X bash chokes on this at the first '(' and I changed it to:
admin_email=`defaults read AddressBookMe ExistingEmailAddress`
which works just fine.
Second:
chmod a+r $user_index
I have no idea how his is supposed to work without 'touch $user_index'
I added:
touch $user_index
to the script.
Third:
conf=`apachectl -V | awk -F= '/SERVER_CONFIG/ {print \$2}'| sed 's/"//g'`
Okay, this actually *works*, but I don't know why it should. In my book, it should choke on the \$2, because the \ is invalid.
I've left it because it works and if it works it isn't wrong, but I would have written:
conf=`apachectl -V | awk -F= '/SERVER_CONFIG_FILE/ {print $2}' | sed 's/"//g'`
which I've tested and also works.
I'd like to know why Apple's first line works.
Fourth:
sed '/#LoadModule php5_module/s/#LoadModule/LoadModule/' $conf | sed "s^[email protected]^\$admin_email^" > $conf_new
The error here is that:
sed "s^[email protected]^\$admin_email^"
doesn't replace [email protected] with the contents of $admin_email.
I don't know what the and are supposed to do, but this just replaces the string '[email protected]' with the string '\$admin_email'
I replaced this with:
sed 's^[email protected]^'$admin_email'^'
This gives me a final script of:
#!/bin/sh
admin_email=`defaults read AddressBookMe ExistingEmailAddress`
user_www=$HOME/Sites
filename=php-test
user_index=${user_www}/${filename}.php
user_db=${user_www}/${filename}-db.sqlite3
conf=`apachectl -V | awk -F= '/SERVER_CONFIG/ {print $2}'| sed 's/"//g'`
conf_old=$conf.$$
conf_new=/tmp/php_conf.new
touch $user_index
touch $user_db
chmod a+r $user_index
chmod a+w $user_db
chmod a+w $user_www
echo "Enabling PHP in $conf ..."
sed '/#LoadModule php5_module/s/#LoadModule/LoadModule/' $conf | sed 's^[email protected]^'$admin_email'^' > $conf_new
echo "(Re)Starting Apache..."
osascript <<EOF
do shell script "/bin/mv -f $conf $conf_old; /bin/mv $conf_new $conf; /usr/sbin/apachectl restart" with administrator privileges
EOF
which works just fine.
But I'm still confused - why did ADC have a code snippet that could have never worked? Or am I missing something obvious?
- NathanHey, RanjeetJones!
You're probably right - it's a lot of code to uncomment a line and change the administrator setting.
And the first time I set up PHP, I just found and edited the config file.
But the script had me so confounded I went back to troubleshoot it and got all wrapped up in why it ended up that way.
And this will help the next coder who wants to learn PHP and maybe doesn't speak bash.
- Nathan -
Help Needed With Scripting and Error Messages
I am working to build a script to change orders in SAP using Java. I begun by recording steps and combining them. I am having issues with the Warning and Error Messages. Can someone help me write language to have the script enter through the warnings or errors if they pop up, but move to the next step if nothing pops up?? Some orders have the message, some do not, some have multiples... etc...
Thanks!!Hello Jamie.
Getting popup you can use an Loop like below (this is now for Excel VBA coded):
For Each subWindow In Session.Children
If subWindow.Name = "wnd[1]" Then
On Error Resume Next
Session.FindById("wnd[1]").sendVKey 0
Session.FindById("wnd[1]/usr/btnANSWER_YES").press
Session.FindById("wnd[1]/usr/btnSPOP-OPTION2").press
End If
Next
For Messages in SAP session statusbar like this:
If Session.FindById("wnd[0]/sbar").Text <> "" Then ...
To catch error Messages defined by messagetype you can use this:
If Session.FindById("wnd[0]/sbar").messagetype = "S" Then ... 'sucess messagetype
If Session.FindById("wnd[0]/sbar").messagetype = "I" Then ... 'Information messagetype
If Session.FindById("wnd[0]/sbar").messagetype = "E" Then ... 'Error messagetype
Aso...like we have in SAP
Hope this help a bit to achieve your requirements.
Best regards,
Holger -
Autmator ruby shell script and regex to perform find and replace
I am trying to create an automator workflow that uses a ruby shell script with regex to replace specified patterns in a text file.
The following works fine to read (and return) the contents of the specified file:
original=IO.read(ARGV.join,nil,2)
changed=original
puts changed
However, if then use gsub to remove the word "BENEFICIARY", the action returns the text unchanged:
original=IO.read(ARGV.join,nil,2)
changed=original.gsub(/"BENEFICIARY"/,"")
puts changed
Using gsub! returns nothing at all.
Any suggestions?This fails due the the spaces in the directory and app name
Right, this is a common problem that many people encounter.
I'm guessing I'm placing the single quotes or using the quoted form... improperly. Can someone please explain how to format a path in this manor.
quoted form is the preferred/recommended way of doing this. Here's an example:
set cmdPath to "/Users/just me/Desktop/Test Project/Test App.app/Contents/Resources/RWplist"
do shell script (quoted form of cmdPath) & " --list"
If you want to build the script manually then you should single-quote the entire path, e.g.:
do shell script " '/Users/just me/Desktop/Test Project/Test App.app/Contents/Resources/RWplist' --list"
Note that there are single quotes around the command path but the --list parameter is outside of the single-quoted path. -
UDM and shell scripts and working with the ENVIRONMENT variable options
In Userdefined metrics you have the ability to pass envronment variables.
I was going to send
DIR=/db/db05/oradata/ORCL/hot
How to handle whats passed to the shell script?
It passes $1 as {DIR=/db/db05/oradata/ORCL/hot}
yes with the brackets. Here I figured it would simply set the DIR environment variable.
Any cool tricks to work with this mess?
Is it meant for perl scripts instead?
Daryl.Ilmari Aalto wrote:
Hi Darth,
Thanks for your hint! Nevertheless I think it's something more profound, since there's no error etc. For example, should I have the path wrong I assume that OWB would return me some kind of an error when it doesn't find the .sh-file? Isn't there any log-file to see whether the command was executed? It seems like the execution of the User Defined element would be skipped altogether.
Cheers,
IlmariNo, if you don't give an absolute path OWB will not return any error, it just wont do anything at all... -
Shell script and escaped spaces
Recently I decided I should do some backing up of my linux partition and the windows paritition so I decided to use dar with a little script to allow a full backup and a differential backup. The problem is that I have some directory names that have spaces in them and when the dar program is called from the script these become normal spaces and so it doesn't work.
What should I do? I would rather write the script in ruby but that seems a bit excessive so it would be better to use a shell script.The latest issue of linux gazette will be of immense help to you. Sorry it is late where I am & I have to get some sleep. I think it is the answer gang, at the end of their section.
linuxgazette.net
There is also freshmeat, which has the latest bash tutorial & ref released within the last couple of days. abs-guide.html.tar.gz -
Problems using Shell scripts and Automator
My problem is that when I use the "Run Shell Script" Automator action, it won't work if I type the script inside the action but it will work if I just type a path to the script file, which is less elegant as I then need to copy the Automator app made as well as the script file.
Here is the script I am trying to use
#!/bin/bash -f
if test -f ~/Library/Preferences/SPACE.com/Pro/Registration\ File
then
open -a /Applications/Starry\ Night\ High\ School/Starry\ Night\ High\ School.app/
else
ditto /Library/Management/Preferences/StarryNight/SPACE.com ~/Library/Preferences/SPACE.com
open -a /Applications/Starry\ Night\ High\ School/Starry\ Night\ High\ School.app/
fi
exit 0Well I found the problem. Or at least I got it to work. I tried typing simple commands and scripts into the Shell Script action and had no issues with it running. So I then slowly expanded and typed out my script:
#!/bin/bash -f
if test -f ~/Library/Preferences/SPACE.com/Pro/Registration\ File
then
open -a /Applications/Starry\ Night\ High\ School/Starry\ Night\ High\ School.app/
else
ditto /Library/Management/Preferences/StarryNight/SPACE.com ~/Library/Preferences/SPACE.com
open -a /Applications/Starry\ Night\ High\ School/Starry\ Night\ High\ School.app/
fi
exit 0
Having typed it out in the script it runs fine. It seems you can't paste text into the action. To test this hypothesis, I copied the working script out of automator into BBedit and then back into Automator, the script no longer worked. Not sure why that is happening, but it does work if I type the scripts out. -
Please guide me with parameter passing at 3 levels. Here is the scenario.
a. A plsql-generateMaster.plsql- invokes stored procedure genMDetails(param1, query)
b. A shell script genM.sh invokes generateMaster.plsql
c. Need to pass date range as parameters (2 dates) to shell script.
d. The shell scripts accepts the date range parameters and passes them to -generateMaster.plsql
e. generteMaster.plsql uses the 2 date parameters to pass as part of query during the invocation of stored procedure genMDetails(param1, query)
In short - shell script->plsql->stored procedure
Platform is Sun Unix 8, oracle db 9i R2
Thanks.This script shows how to pass parameters to PL/SQL anonymous block.
sqlplus "mob/mob" << EOF
set serveroutput on
begin
dbms_output.put_line('Parameter one: ' || '$1');
dbms_output.put_line('Parameter two: ' || '$2');
-- Here you can invoke procedure proc1($1,$2);
end;
EOF
You can just invoke it like this:
./passParameters.sh 12-13-1981 03-04-2006
Best Regards
Krystian Zieja / mob -
Shell script and keyboard shortcut
I wrote a bash script, and I would like to start it with a keyboad shortcut, but I can't figure out how to do that. Does anyone know?
Hi Hugo,
Keyboard shortcuts are meant for Carbon and Cocoa applications but it can be done; you just have to wrap the shell script in some sort of application. One way is Sveinbjorn Thordarson's Platypus but I just wrap mine with an AppleScript, invoking it with "do shell script". You have to save the AppleScript as an application. Then you open the "Keyboard & Mouse" pane of "System Preferences" and select the "Keyboard Shortcuts" tab. Click the plus sign, '+', pick a key combination and specify your AppleScript or Platypus app as the target.
Gary
~~~~
Are there those in the land of the brave
Who can tell me how I should behave
When I am disgraced
Because I erased
A file I intended to save? -
I need a 2 way sync tool for the mac (or a shell script and some help)
I am looking for a way to (two way) sync a folder on my Macbook Pro with a SMB Server (aka Windows)
I found a few paid for applications that do this, and before I buy one I thought I'd ask here and see if there are any recommendations.
So far I've found Synk Standard and ChronoSync.
I assume this could also be hacked together with Automator and some shell scripts, but I'm not sure how I'd do that.yes, Chronosync is often recommended for this kind of thing. Never heard of Synk Standard. you can also do it for free with rsync but I suggest you stick with Chronosync.
Maybe you are looking for
-
Why can I drag and drop from Photos to Pages, but not to Microsoft Word 2011
I'm unable, under OS X 10.10.3, to drag and drop pictures from Photo into Word for Mac 2011. I can paste from Photos into Pages. How can I add Word to the list of programs that can take pasted photos pasted from Photos
-
Activate photoshop elements 12 on multiple computers
Hello Im trying to rollout photoshop elements 12 to 30 pc's Tried the slient install method by putting the serial number and ul in the command line and creating the application.xml.override file which works On launching the programme it s asking for
-
How I fixed the 'network host busy" error
I've been down for a day solving the "network host busy' error. First, I had fits trying to hook up this HP to my system. Here's the thread on that: http://forums.techguy.org/networking/858081-laserjet-4500-mac-osx-10-a.html Once all that was done, i
-
I have recently changed jobs but kept my iPad. I have managed to change my apple ID to my new (personal) email address which is fine but I know I have previously bought stuff from the App Store so need to also be changing my billing/account details b
-
Have NEW ‘Canon MX432’, (1)-followed the instructions to set language without problem, next step, checked for the Set ink cartridge Message, (2)-and then opened the Paper Output Tray and the Paper Output Cover. On the second try; (3)-the Head Cover o