Help wrt to Unix script using egrep
In one of our script, we are checking whether already an instance of process is running in the system using the commands ps and egrep.
An intermediate process is created with the same name as original process before invoking the egrep, which is resulting the result of grep to be incorrect.
The following code is in the script /opt/check.sh is resulting in the problem.
RESULT=`/usr/ucb/ps -auxww | egrep "/opt/check.sh ${PARAM}" | grep -v "log" | grep -v "grep" `
The above code is
solaris9{root} #: ps -ef | egrep "/opt/check.sh"
nmsadm 11500 11498 0 10:45:16 pts/6 0:00 egrep /opt/check.sh -s
nmsadm 11498 11431 0 10:45:16 pts/6 0:00 /bin/sh /opt/check.sh -s
nmsadm 11431 28568 0 10:45:13 pts/6 0:00 /bin/sh /opt/check.sh -s
solaris9{root} #: ptree 11498
We are using solaris9.
If anyone has any idea pleas let me know.
Thanks in advance
OK, I agree, current script will be also displayed, but my solution is still better ;)
pgrep -x program_name | grep -v $$
One line, and so easy. But if you really want to have only one instance of some script at the time I propose you another solution:
#!/bin/bash
# location of lock file, /var/run is quite good place because it's empty
# after every reset (virtual filesystem placed in memory). Many of other
# Solaris application puts his lock files here
LOCK=/var/run/somescript.lock
# check if there is lock file
if [ -e $LOCK ]
then
# some error message
echo "Another instance is running allready. Exiting." >&2
# if you want to now everything about running instance
ps -fp `cat $LOCK`
# exiting now
exit 1
fi
# to be sure that lock file will be deleted at the end of execution
trap 'rm -f $LOCK' EXIT
# here lock file with process PID is created
echo $$ > $LOCK
< here is the rest of your script unchanged>
This solution is better if you only want to be sure, that there is only one instance of process running at one time. Previous one, with pgrep, if you want to check if another script is running. I missunderstood your question at the beginning.
Hope this helps.
Regards
Similar Messages
-
Calling unix script using oracle forms
we have to call unix script using oracle forms , a trigger in form calls stored procedure on database
that stored procedure on database calls a oracle shared library
but since the only listener account for oracle on our unix server is oralist , whenever a call is made to the unix script from the oracle form , the unix script is executed by oralist user
but issue that we are having now is since oralist is specific for listening connections from orale we dont want to use this user to establish SFTP on it to avoid any issues with oralist
we want the sftp to be established on soem other useraccount , so is it possible to do something so that the script is executed by an account other that oralist.I'm not a Linux/Unix specialist, but I think this may work: let your database call a shell script that does a su command before running the actual script:
su - other_account
your_script.sh -
Need help to modify vb script used in XP for Windows 7
Can somebody help me in modifying scripts that were used for Windows XP, to run on Windows 7.
My friend advised me to change it to .ps1, but still some flaws..
Cscript \\nologo ???? is used for what purpose ?Almost all VBScripts written to work in Windows XP will also work for Windows 7, so there's not much to modify (unless you have specific examples of scripts not working).
Having said that, PowerShell is the future! It takes a bit more than to just change the file extension to .ps1 though (this may be why your scripts aren't working!).
The VBScript-to-Windows PowerShell Conversion Guide
http://technet.microsoft.com/en-us/library/ee221101.aspx
C:\>cscript /?
Microsoft (R) Windows Script Host Version 5.7
Copyright (C) Microsoft Corporation. All rights reserved.
Usage: CScript scriptname.extension [option...] [arguments...]
Options:
//B Batch mode: Suppresses script errors and prompts from displaying
//D Enable Active Debugging
//E:engine Use engine for executing script
//H:CScript Changes the default script host to CScript.exe
//H:WScript Changes the default script host to WScript.exe (default)
//I Interactive mode (default, opposite of //B)
//Job:xxxx Execute a WSF job
//Logo Display logo (default)
//Nologo Prevent logo display: No banner will be shown at execution time
//S Save current command line options for this user
//T:nn Time out in seconds: Maximum time a script is permitted to run
//X Execute script in debugger
//U Use Unicode for redirected I/O from the console
C:\>
Andreas Hultgren
MCTS, MCITP
http://ahultgren.blogspot.com/ -
How to Access UNIX scripts using Java
folks,
Is there any way we can access UNIX scripts or CRON Jobs in java, I am planning to come up with some monitoring tool for our application and in these i need to monitor the UNIX scripts whether its running or not ,
Let me know if any of you guys done this,
Regards
MathewCheck the java.lang.Runtime object and exec(...) methods.
Marc -
Help with 2 UNIX Commands using ARD
Hello All,
Can someone help me with 2 UNIX commands I would like to set up? The first one... how to delete a range of users within /Users by date (i.e. the oldest user who last logged in "Mar 22 09:40 00796216" to "Mar 25 17:01 01036773"). Currently, I'm using "sudo rm -r " followed by each home directory name separated by a space. It works but to save time, it would be nice to do this all within 1 UNIX command.
Second, is there a UNIX command where I can delete a range of users by ID numbers? (We have users assigned with an 8 digit ID number. Is there a UNIX command where I can delete users from 12345678 to 23456781?) Again, I'm using "sudo rm -r " followed by each home directory name separated by a space.
Thank you in advance!
MikeThis happens with or without SIM card, with and without wifi... with and without SD card as well-- even bought a new 32GB class 10 SanDisk-- but it still crashed.
Just an update: Went to the Nokia Care Center yesterday, they reflashed the firmware and I got back the phone within the day... when I went back home to try the phone again... again it kept hanging... in a period of 5 minutes, I had 5 hangs... right from startup, went straight to the cam, took some pics then pinched zoom... and phone simply crashed-- had no SD car, no sim card then.
So today I went back to Nokia Care Center... they said they will do some more tests and see... but they insist its a software problem, we'll see in a day or 2. -
Help needed in Unix script for oracle 9i
Hi gurus,
I'm working on oracle 9i in solaris, i would like to calculate the amount of archived logs generate per day. Can anyone please help me to find that.
ThanksPut the following lines in a script and it should work for you.
SET feedback off
SET line 200
COL NAME FOR a100
-- counts the no of archives generated today
select count(*) "No. of Logs for today" from v$archived_log where to_char(completion_time,'DD-MON-YY')=to_char(sysdate,'DD-MON-YY');
-- lists all archive generated for the day
select name,blocks*block_size as "Size in KB" from v$archived_log
where to_char(completion_time,'DD-MON-YY')=to_char(sysdate,'DD-MON-YY');
-- shows total size in KB
select sum(blocks*block_size) "Total Log Size for day in KB" from v$archived_log
where to_char(completion_time,'DD-MON-YY')=to_char(sysdate,'DD-MON-YY');
Hope this helps.
Thanks
Siba -
Hi,
I have the following script that is supposed to search AD for all user accounts that haven't logged into the domain in more than 90 days. I first did not have the where-object clause because I didn't realize the search-adaccount would provide results
back of users that have never logged in, but were created less than 90 days ago. So I tried to incorporate the logic to not include user accounts that were created in the last 90 days.
#requires -version 4
#This script creates a file of accounts that have not been logged into in the past 90 days, excluding accounts that have been created within the past 90 days since the -AccountInactive option does not factor for the whenCreated property of an AD object
$DateThreshold = ((Get-Date).AddDays(-90))
$ReportDate = Get-Date -Format yyyy-MM-dd
#Create a folder according to the current date to be used for storing the report
New-Item -Path ".\$ReportDate" -ItemType Directory
$InactiveUsers = Search-ADAccount -UsersOnly -AccountInactive -TimeSpan "90" -SearchBase "OU=XXXX,DC=XXXX,DC=XXXX,DC=XXXX" | Where-Object {$_.whenCreated -gt $DateThreshold} | Export-Csv ".\$ReportDate\Inactive90_$ReportDate.csv"
However, I can't ever get the whenCreated field to populate with data. What gives?Hi,
Search-ADAccount doesn't return a whenCreated property. If you want that, you'll need to use Get-ADUser as well. Here's a basic example you can build from:
$dateThreshold = (Get-Date).AddDays(-90)
Search-ADAccount -UsersOnly -SearchBase 'OU=Users,DC=domain,DC=com' -AccountDisabled | ForEach {
$whenCreated = (Get-ADUser -Identity $_.SamAccountName -Properties whenCreated).whenCreated
If ($whenCreated -gt $dateThreshold) {
$_
Don't retire TechNet! -
(Don't give up yet - 12,950+ strong and growing) -
Need Help Writing a Calculation Script Using a Checkbox
Hello,
I am new to Adobe X Standard and Javascript. I have all other parts of my fillable change order form completed except the tax calculation. I have the following fields:
Text Field = SUBTOTAL
Text Field = TAX
Checkbox = Exempt
I would like the calculation in the TAX field to be as follows:
If the checkbox = false then SUBTOTAL * .05, else SUBTOTAL = 0.
It really doesn't seem that complex but learning javascript on the fly is apparently above my skill level. I would greatly appreciate someone's help in getting this initial calculation working. I greatly appreciate your time. Thank you.Your description is a bit confusing to me. Do you want to calculate the value of the TAX field? In the last bit of pseudocode, you seem to be setting SUBTOTAL to 0. Do you want the tax to be the SUBTOTAL value times 0.05 if not exempt and 0 if exempt? If so, the custom calculate script of the TAX field can be:
event.value = getField("Exempt").value === "Off" ? +getField("SUBTOTAL").value * 0.05 : 0;
This is equivalent to:
if (getField("Exempt").value === "Off") {
event.value = +getField("SUBTOTAL").value * 0.05;
} else {
event.value = 0; -
File port query File transfer from SAP R/3 to Webmethods using Unix Script
SAP drops the files in the /sapio/ directory and triggers an unix script using File port partner destination.
Unix script will perform a secure copy of files to Webmethods server.
If in unix script, error occurs then an RFC function will be called to send an error notification to a person.
Queries
1) How is the unix script triggered using the File port partner destination ?
2) What is the unix command to invoke a report which sends the error notification mail ?
3) Does SCP command to copy files to webmethods work , if the unix script is placed in /sapio/ directory ? Or whether
any connection need to be established between SAP and Webmethods server ?Hello,
Since you want to transfer Article Master, it should be a Retail System. So you should use Message Type ARTMAS. For fullbuild, you can use transaction WDBM and for changes, you can use WDBU. For changes, you can enable change pointers for required fields using BD64.
Thanks,
Venu -
Executing a UNIX shell script using SM49
I have been trying all sorts of things to get this to work and I have been un-successful
I am trying to run the UNIX script using SM49. the command line that I am using is
/test/directory/bin/testmail.sh
the script testmail.sh looks like
#!/bin/ksh
/usr/bin/mailx -s testmail <email address>
I have tried all sorts of combinations to run this script
example
sh /test/directory/bin/testmail.sh
/test/directory/bin/testmail.sh %f
/test/directory/bin/testmail.sh %F
does anyone have any suggestions on how to get this to run successfully. once I get this to run successfully in SM49, I am going to try it in the intregration builder of my PI process.Hi,
considering authorization issues, you can use
CALL FUNCTION 'SXPG_COMMAND_EXECUTE'
EXPORTING
commandname = 'LIST_DB2DUMP'
additional_parameters = l_path
operatingsystem = 'UNIX'
TABLES
exec_protocol = lt_btcxpm
EXCEPTIONS
to extract information about files on the server
I used this code to get detailed information for display including the attributes
LOOP AT lt_btcxpm ASSIGNING <btcxpm>
WHERE length > 57
AND ( NOT message+57 CO '. '
OR message+57 = '..' )
AND ( message(1) = 'd' OR
message(1) = 'l' OR
message(1) = '-' ).
l_srvfil-type = <btcxpm>-message(1).
IF l_srvfil-type = '-'.
l_srvfil-type = 'F'.
ENDIF." l_srvfil-type = '-'.
TRANSLATE l_srvfil-type TO UPPER CASE. "#EC TRANSLANG
l_srvfil-file = <btcxpm>-message+57.
CONDENSE l_srvfil-file.
l_srvfil-attri = <btcxpm>-message+1(9).
* l_srvfil-time = <btcxpm>-message+44(12).
l_srvfil-size = <btcxpm>-message+32(11).
APPEND l_srvfil TO lt_srvfil.
ENDLOOP." at lt_BTCXPM assigning <BTCXPM>.
pt_srvfil = lt_srvfil.
For the srvfil information I used this structure
BEGIN OF typ_srvfil,
%_box TYPE flag, "#EC *
type TYPE char01,
attri TYPE isp_rel,
file TYPE file,
name TYPE file,
size TYPE sytleng,
owner TYPE sy-uname,
mod_date TYPE sydatum,
mod_time TYPE syuzeit,
END OF typ_srvfil,
I do not remember exactly how the attribute information is resolved. In Unix all file system authorizations can be set as for the user, the group or for all and it can be read, write, execute granted. If you are no unix expert, ask one or google/wiki for some details.
I wrote a program for navigation, display, and some more functions on the file system which is too big to post here and is not fully system-independent. Not perfect but useful and more than 5 years old. Contact me by mail if you want it.
Regards,
Clemens
Edited by: Clemens Li on Oct 23, 2009 9:16 PM -
Hi All,
Hope you can help me in know
where to find some help doc's on scripts used in BPC and coding in SSIS packeges.
And does BPC internally convert scripts to SQL script or MDX?
And can i use both SQL and MDX in single logic file?
Any help will be greatly appriceatedThe BPC logic engine converts the "SQL-style" script logic syntax into true SQL, that's executed against the data in the fact tables.
MDX script logic is executed against the Analysis Services cubes; I don't believe that much conversion is involved here, but honestly I'm not an MDX expert, so I could be mistaken.
You can mix both in a single logic file, subject to a clear understanding of how *COMMIT and XDIM_Member, etc. work to scope a particular block of code. The BPC Admin guide (also in the online admin help) is the key reference guide for this.
But the most important piece of advice I can give is, don't write MDX logic. Only use it (as sparingly as possible) for raios (division) in member formulas, where you need to evaluate a formula at various points in the hierarchy (not just at base members). For everything else, use business rules or SQL logic. -
How can I exit my UNIX script when my PLSQL script in it calls an error?
hello.
I hope someone can help with my error handling and exiting-in-the-right-place problem.
I have several PLSQL scripts that are called from a UNIX script to insert/update employee records in ORACLE Financials.
At the end of the UNIX script, depending on whether an entry has been created in the errors table should depend on whether the UNIX script stops or not. Trouble is, its stopping too early everytime even though the the record has been inserted correctly. Please can someone either advise on what I'm doing wrong or suggest an alternative..
This the end of the PLSQL script that inserts the entry into errors table if theres an error..
WHEN OTHERS THEN ROLLBACK;
err_msg := SUBSTR (SQLERRM, 1, 350);
insert into kpmg_error_check (concurrent_id,module,narrative,status,creation_date,created_by)
values(0,'TEMPLOYEE_DTLS.sql',err_msg,'ERROR',SYSDATE,'Feldman');
commit; This is the end of the UNIX script that looks at the table..
echo " "
echo "**** `date +%H:%M:%S` - Checking if TEMPLOYEE_DTLS.sql ran OK"
error_check=`sqlplus -s $user_id @$SU_TOP/sql/SUTEMPCHK.sql 1`
if `echo $error_check` -ge 1
then
# Load failed
echo " "
echo "**** `date +%H:%M:%S` - TEMPLOYEE_DTLS has failed - check table KPMG_ERROR_CHECK for details.."
exit 1
else
# Load finished OK, if input data file exists, move and rename it
echo " "
echo "**** `date +%H:%M:%S` - TEMPLOYEE_DTLS has finished OK.."
fiThis is the entire SUTEMPCHK.sql script that the UNIX script uses..
-- Check if any errors have occurred
SELECT count(1) FROM kpmg_error_check WHERE concurrent_id = &1
EXITIs it that the above is always returning '1' and so always thinks theres an entry in the errors table?
Is there an easier way?
many thanks,
StevenHi,
You have to iterate through all pages.marginPreferences:
var
myDocument = app.activeDocument,
allPagesMaPref = myDocument.pages.everyItem().marginPreferences,
curPageMaPref;
while ( curPageMaPref = allPagesMaPref.pop() )
with (curPageMaPref) {
columnCount = 1;
//columnGutter can be a number or a measurement string.
columnGutter = "0";
bottom = "0"
//When document.documentPreferences.facingPages == true,
//"left" means inside; "right" means outside.
left = "40"
right = "0"
top = "0"
inside = "0"
Jarek -
Hi..
The requirement is as follows :
SAP drops a file into a folder and triggers a UNIX script using a File Port partner destination.
Unix script will perform a secure copy to the Webmethods server. If a Unix script error occurs, an Rfc function will be called to send an error notification to a particular contact person.
Can anyone help me how is the unix script triggered from SAP ?
Thanks in advanceYou can execute this sample code:
Data: unix_cmd(50).
unix_cmd = 'chmod 664 /sapdata/DEV/home/travelers'.
translate unix_cmd to lower case.
call 'SYSTEM' id 'COMMAND' field unix_cmd.
write: / sy-subrc.
OR
Create and run a UNIX command programmatically
The destination must be set up and configured from tcode SM59
see note OSS 63930
rfcexec, this service must be started from UNIX
UX syntax to start service:
rfcexec -aUNIX_COMMAND -g sap01 -x sapgw00 &
rfcexec - program, /sapmnt/DEV/exe
UNIX_COMMAND - program ID from SM59, case sensitive
sap01 - AP_Gateway_hostname
sapgw00 - Gateway_Service
Transaction SMGW, monitor the gateway (Goto/Logged on clients)
*Number LU name TP Name Syst.type Host name Host address
0 sap01 sapgw00 LOCAL_R3 sap01 10.1.193.50
233 sap01 UNIX_COMMAND REGISTER_TP sap01 10.1.193.50
Could replace this unsupported SAP syntax, Call 'SYSTEM'
*data: begin of tabl occurs 0,
line(200),
*end of tabl.
*call 'SYSTEM' id 'COMMAND' field comm
id 'TAB' field tabl-sys.
data: command(256).
data : begin of ret occurs 10, " results of unix command
text(80),
end of ret .
data: i_connected_systems type table of gwy_system.
data: w_connected_systems type gwy_system.
data: w_message(80).
parameter: p_junk(4) default 'Junk'.
start-of-selection.
call function 'GWY_READ_CONNECTED_SYSTEMS'
EXPORTING
GWHOST =
GWSERV =
DISCONNECT =
tables
connected_systems = i_connected_systems
EXCEPTIONS
GWY_UNKNOWN_OPCODE = 1
GWY_COMMUNICATION_FAILURE = 2
GWY_GET_TAB_FAILED = 3
GWY_NEWLINE_FAILED = 4
GWY_TABLEN_TOO_SHORT = 5
GWY_GET_OPCODE_FAILED = 6
GWY_GET_GWHOST_FAILED = 7
GWY_GET_GWSERV_FAILED = 8
GWY_MONITOR_DISABLED = 9
OTHERS = 10
if sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
read table i_connected_systems into w_connected_systems
with key tpname = 'UNIX_COMMAND'.
if sy-subrc ne 0.
perform display_error_messages.
stop.
endif.
*COMMAND = 'ls '. " command
*COMMAND = 'ls -lt'. " command, newest at top
command = 'ls -osra'.
call function 'RFC_REMOTE_PIPE'
DESTINATION 'SERVER_EXEC'
destination 'UNIX_COMMAND'
exporting
command = command
read = 'X'
tables
pipedata = ret.
loop at ret.
write ret.
endloop.
end-of-selection.
*& Form Display_error_messages
form display_error_messages .
data: begin of listtab occurs 0,
field(80),
end of listtab.
listtab-field = 'Program UNIX_COMMAND is not registered.'.
append listtab.
listtab-field = 'Tell Basis person about the error'.
append listtab.
listtab-field = ' '.
append listtab.
listtab-field = 'UX syntax to start service: '.
append listtab.
listtab-field = 'rfcexec -aUNIX_COMMAND -g sap01 -x sapgw00'.
append listtab.
listtab-field = ' '.
append listtab.
listtab-field = 'Program aborted,'.
listtab-field+19 = sy-cprog.
append listtab.
call function 'POPUP_WITH_TABLE_DISPLAY_OK'
exporting
endpos_col = 70
endpos_row = 20
startpos_col = 10
startpos_row = 10
titletext = 'Registered program error'
IMPORTING
CHOISE =
tables
valuetab = listtab
EXCEPTIONS
BREAK_OFF = 1
OTHERS = 2
if sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
endform. " Display_error_messages
Bruce -
Need Help in creating Unix Shell Script for database
Would be appreciable if some one can help in creating unix shell script for the Oracle DB 10,11g.
Here is the condition which i want to implement.
1. Create shell script to create the database with 10GB TB SPACE and 3 groups of redo log file(Each 300MB).
2. Increase size of redolog file.
3. Load sample schema.
4. dump the schema.
5. Create empty db (Script should check if db already exists and drop it in this case).
6. Create backup using rman.
7. restore backup which you have backed up.This isn't much of a "code-sharing" site but a "knowledge-sharing" site. Code posted me may be from a questioner who has a problem / issue / error with his code. But we don't generally see people writing entire scripts as responses to such questions as yours. There may be other sites where you can get coding done "for free".
What you could do is to write some of the code and test it and, if and when it fails / errors, post it for members to make suggestions.
But the expectation here is for you to write your own code.
Hemant K Chitale -
Changing the filenames using unix script
Hi,
I have a scenario where I have to change the file names on the Receiver CC using a unix script and add date and timestamp to the file name
this is what I'll be writing to filename_01.xml I need to change that to newfilename_01_MMDDYYYY_HHMISS.xml
the 01 in the file name is the counter, so I might having more than one file where 01,02, etc will represent the counter on the filename.
Any help is really appreciated.
Thanks,
Joe.Pyou can try this
create the field called filename in target
use a costant and concat it with the out out of UDF( or some functon avaleiable counter) which will genereate numbers like 1,2,3,4,5,6 and send this filename_01 to the output field and use this in the variable substution to genreate the filename by the CC
if you dnt want to send this fieldin output file then specify that fieldname in CC length as 0
Maybe you are looking for
-
Unable to send emails from any Apple devices
Since BT made the changes to Yahoo mail i have had problems with sending emails from my ipad and iphone (IOS8). The only way that i can successfully send an email is to log onto my laptop and send from a windows platform. I have checked all of the se
-
Refund amount and disable auto charge for subscrip...
Hello , Here is my order number ****************272 Please refund the amount and how can i disable auto recharge option ? I want it for USA but unfortunately subscribed for UK .. Please help Thanks
-
Lvwutil32 & TS4.x with LV8.5 RTE
Hi, I am trying to complete a TS4.0.1 + LV8.5.1 RTE deployment that uses functionality within the lvwutil32 utilities. Everything if OK with LV8.5.1 development environment but TS+LV crash out when I change over to the RTE. I believe this is because
-
The operations can't be completed because you don't have the necessary permission
Randomly my MacBook running OS X Mountain Lion 10.7.4 would not let me copy files to my desktop or create a new folder on my desktop. When ever I try to do either it asks me to put my password in and then I get this error message: "The operations can
-
How To insert the mobile company chip
How to insert a mobile company chip into i phone