How to unzip files in Shell script
Hi Gurus,
I have one requirement, where in I need to unzip files at at unix level and then move to the respective folders. How can I code this in the shell script.
As it is entirely new thing, please let me know how to do this. Seeking few program steps.
Thanks in advance for your help.
Regards
Nagendra
You can specify unzip -d directory to tell unzip where to extract the files. For instance:
dest_dir="/tmp/$(date +%N)"
# zip file is cmd line argument $1
unzip -d $dest_dir "$1"
cd $dest_dirI don't know of any way to automatically go to a zip'ed directory stored inside the zip file. Besides, where do you want to go in case there are several directories stored?
Similar Messages
-
How to get ORA errors in alertlog file using shell script.
Hi,
Can anyone tell me how to get all ORA errors between two particular times in an alertlog file using shell script.
ThanksHi,
You can define the alert log as an external table, and extract messages with SQL, very cool:
http://www.dba-oracle.com/t_oracle_alert_log_sql_external_tables.htm
If you want to write a shell script to scan the alert log, see here:
http://www.rampant-books.com/book_2007_1_shell_scripting.htm
#!/bin/ksh
# log monitoring script
# report all errors (and specific warnings) in the alert log
# which have occurred since the date
# and time in last_alerttime_$ORACLE_SID.txt
# parameters:
# 1) ORACLE_SID
# 2) optional alert exclusion file [default = alert_logmon.excl]
# exclude file format:
# error_number error_number
# error_number ...
# i.e. a string of numbers with the ORA- and any leading zeroes that appear
# e.g. (NB the examples are NOT normally excluded)
# ORA-07552 ORA-08006 ORA-12819
# ORA-01555 ORA-07553
BASEDIR=$(dirname $0)
if [ $# -lt 1 ]; then
echo "usage: $(basename) ORACLE_SID [exclude file]"
exit -1
fi
export ORACLE_SID=$1
if [ ! -z "$2" ]; then
EXCLFILE=$2
else
EXCLFILE=$BASEDIR/alert_logmon.excl
fi
LASTALERT=$BASEDIR/last_alerttime_$ORACLE_SID.txt
if [ ! -f $EXCLFILE ]; then
echo "alert exclusion ($EXCLFILE) file not found!"
exit -1
fi
# establish alert file location
export ORAENV_ASK=NO
export PATH=$PATH:/usr/local/bin
. oraenv
DPATH=`sqlplus -s "/ as sysdba" <<!EOF
set pages 0
set lines 160
set verify off
set feedback off
select replace(value,'?','$ORACLE_HOME')
from v\\\$parameter
where name = 'background_dump_dest';
!EOF
`
if [ ! -d "$DPATH" ]; then
echo "Script Error - bdump path found as $DPATH"
exit -1
fi
ALOG=${DPATH}/alert_${ORACLE_SID}.log
# now create awk file
cat > $BASEDIR/awkfile.awk<<!EOF
BEGIN {
# first get excluded error list
excldata="";
while (getline < "$EXCLFILE" > 0)
{ excldata=excldata " " \$0; }
print excldata
# get time of last error
if (getline < "$LASTALERT" < 1)
{ olddate = "00000000 00:00:00" }
else
{ olddate=\$0; }
errct = 0; errfound = 0;
{ if ( \$0 ~ /Sun/ || /Mon/ || /Tue/ || /Wed/ || /Thu/ || /Fri/ || /Sat/ )
{ if (dtconv(\$3, \$2, \$5, \$4) <= olddate)
{ # get next record from file
next; # get next record from file
# here we are now processing errors
OLDLINE=\$0; # store date, possibly of error, or else to be discarded
while (getline > 0)
{ if (\$0 ~ /Sun/ || /Mon/ || /Tue/ || /Wed/ || /Thu/ || /Fri/ || /Sat/ )
{ if (errfound > 0)
{ printf ("%s<BR>",OLDLINE); }
OLDLINE = \$0; # no error, clear and start again
errfound = 0;
# save the date for next run
olddate = dtconv(\$3, \$2, \$5, \$4);
continue;
OLDLINE = sprintf("%s<BR>%s",OLDLINE,\$0);
if ( \$0 ~ /ORA-/ || /[Ff]uzzy/ )
{ # extract the error
errloc=index(\$0,"ORA-")
if (errloc > 0)
{ oraerr=substr(\$0,errloc);
if (index(oraerr,":") < 1)
{ oraloc2=index(oraerr," ") }
else
{ oraloc2=index(oraerr,":") }
oraloc2=oraloc2-1;
oraerr=substr(oraerr,1,oraloc2);
if (index(excldata,oraerr) < 1)
{ errfound = errfound +1; }
else # treat fuzzy as errors
{ errfound = errfound +1; }
END {
if (errfound > 0)
{ printf ("%s<BR>",OLDLINE); }
print olddate > "$LASTALERT";
function dtconv (dd, mon, yyyy, tim, sortdate) {
mth=index("JanFebMarAprMayJunJulAugSepOctNovDec",mon);
if (mth < 1)
{ return "00000000 00:00:00" };
# now get month number - make to complete multiple of three and divide
mth=(mth+2)/3;
sortdate=sprintf("%04d%02d%02d %s",yyyy,mth,dd,tim);
return sortdate;
!EOF
ERRMESS=$(nawk -f $BASEDIR/awkfile.awk $ALOG)
ERRCT=$(echo $ERRMESS|awk 'BEGIN {RS="<BR>"} END {print NR}')
rm $LASTALERT
if [ $ERRCT -gt 1 ]; then
echo "$ERRCT Errors Found \n"
echo "$ERRMESS"|nawk 'BEGIN {FS="<BR>"}{for (i=1;NF>=i;i++) {print $i}}'
exit 2
fi -
Can any one tell me how can i call a shell script from pl/sql
i like to call shell script from pl/sql procedure.
can any one suggest how can i do thisHave you not mastered in asking the same kind of question ?
First do write a script...
no one will spoon feed you.
How can i call a shell script from procedure
How to call Shell Script from pl/sql block
-Sk -
How can i call a shell script from procedure
I have a shell script.now i am i a situation to call that shell script from one of my procedures and need to get a value from that script.
can u suggest me that how can a call the shell script from pl/sql?Is the same question you asked here
How to call Shell Script from pl/sql block
-SK -
Can I call host file ( Unix Shell script ) from Oracle 10g trigger
Hi,
I am new to Oracle 10g. Can I call host file ( unix shell script ) from Oracle 10g trigger ?. I know it is possible. Pl explain me with small example
thanks & regards
paraguser12009546 wrote:
Hi,
I am new to Oracle 10g. Can I call host file ( unix shell script ) from Oracle 10g trigger ?. I know it is possible. Pl explain me with small example
thanks & regards
paragIf you are in 10g, you can simple call shell script from DBMS_SCHEDULER:
BEGIN
DBMS_SCHEDULER.CREATE_JOB (
job_name => 'TEST_SCRIPT',
job_type => 'EXECUTABLE',
job_action => 'PATH_OF_YOUR_SCRIPT',
start_date => SYSDATE,
repeat_interval => 'FREQ=MINUTELY; INTERVAL=1',
enabled => TRUE,
comments => 'Shell script from Oracle'
END;
/ -
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 -
How do i create a "shell script" as root? [SOLVED]
Really a newbie question, i know, but any how.
I just downloaded and installed a google-drive client and is about to set it all up. Following a guide from github.
https://github.com/astrada/google-drive … tomounting
"Create a shell script named gdfuse in /usr/bin (as root) with this content:"
There were no explanation how to create a shell script. So i just want to know how du i do that?
I assume it's really simple, when logged in as su in a terminal, but shell script is new to me.
I read a tutorial on creating scripts, (http://linuxcommand.org/wss0010.php) but dont know how to create the actual file. e.g. if i open leafpad and try to save it in the /usr/bin i presume it's not as root. Or shall i open thunar as root and do it that way?
Last edited by dockland (2015-06-19 21:39:44)There's seldom need to run graphical application as root. For editing as root, it's best to stick to a text-based editor.
One of the first hits on a ddg search for 'how to create a shell script' was http://www.linfo.org/create_shell_1.html
Last edited by karol (2015-06-19 21:57:23) -
Calling HTML File in Shell Script.
Hi
I have a shell script and a HTML file.
HTML file is to create a Table.
the HTML Script is as follows
<html>
<body>
<table border="1">
<tr>
<td>Requisition Number</td><td>$PARAM0</td>
</tr>
<tr>
<td>Purcahse Order Number</td><td>$PARAM4</td>
</tr>
<tr>
<td>Purchase Line Number</td><td>$PARAM5</td>
</tr>
<tr>
<td>Hold Reason</td><td>$PARAM3</td>
</tr>
<tr>
<td>Hold Date</td><td>$PARAM2</td>
</tr>
</table>
</body>
</html>
The output of this HTML file is a table with 5 rows and 2 columns.
I saved this file as mail.html and placed it in the server where i have placed the Shell Script.
When i call this HTML in Shell Script ... as follow
cat /FND_TOP/bin/mail.html
the output is not the table but infact the html tags are displayed.
I need the table when i run this shell script.
It would be of great help if anyone has a good solution for this.
Thanks in AdvanceFirst, you need to put the file where your httpd server (you will need apache running) can find it. This is usually some place like:
/var/www/html/table.htmlThen use a text-mode browser as Frits suggested to render it so your script can read it:
#!/bin/sh
lynx -dump http://localhost/table.html | while read row; do
echo "${row}"
doneor how ever you want to process the data.
Another approach is to use XML transformations. First write an XML stylesheet:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fn="http://www.w3.org/2005/02/xpath-functions" version="1.0">
<xsl:output indent="no" method="text" standalone="yes" version="1.0"/>
<xsl:template match="*">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="td">
<xsl:text> </xsl:text>
<xsl:value-of select="normalize-space()"/>
</xsl:template>
</xsl:stylesheet>and then run your HTML through the {font:Courier}xsltproc{font} processor:
$ xsltproc table.xsl table.html
Requisition Number $PARAM0
Purcahse Order Number $PARAM4
Purchase Line Number $PARAM5
Hold Reason $PARAM3
Hold Date $PARAM2To be neat, I have omitted the many blank lines that were also output.
HTH -
Return Files from shell script
I have an automator workflow I'm working on that will take FLACs and convert them to AIFF. I do the brunt of the work in a bash script. I have that working just fine, but I'm wanting to output an array (or however I need to do it) of files to then pass to "Import Audio Files". How could I output something that "Import Audio Files" will like from my shell script? Thanks.
... nevermind. *slaps himself in the head* Just echoing works...
-
How do I run a shell script via AppleScript?
Seems obvious, "do shell script" but that doesn't work for me.
I have an Automator app which runs a shell script, I'd like to take that into an AppleScript. My AS doesn't run the shell script. Perhaps "do shell script' is expecting the script to be located elsewhere? The rest of my AS runs fine, but the shell script doesn't.
repeat with i from 1 to count of items in exportFolder
do shell script
"exiftool -overwrite_original -Photoshop:CopyrightFlag='True'"
done
end repeat
As I say this works within an Automator app, what changes do I need to make it work in AppleScript?
Thanks!Camelot wrote:
repeat with i from 1 to count of items in exportFolder
What is 'exportFolder'? Where is it defined?
Thanks, 'exportFolder' is defined earlier in the script. The purpose of the script - which is run from within Aperture - is to rename the selected images, export them (to the 'exportFolder'), reset the version name and, using ExifTool, add metadata which Aperture does not write to exported JPEGs.
I have a version of this which works in Automator but I couldn't see any clues there on setting the path to ExifTool.
Here's the full (modified) script. Currently it returns an error
Result:
error "No file specified" number 1
so I now need to understand if I can use 'exportFolder' (defined at the start) to tell Finder which folder to use.
-- Creating filenames by making Version Name from the IPTC Headline and Filename (with hypens where spaces exist). The Aperture Version Name is used to create the file's name on export. Once exported the Aperture Version Name is reset to its original.
tell application "System Events"
set exportFolder to (choose folder with prompt "Choose an export folder")
end tell
tell application "Aperture"
set theSel to (get selection)
if theSel is {} then
error "Please select an image or two!."
else
repeat with theImg in theSel
-- Creating a new Aperture Version Name which will become the exported file's filename.
tell theImg
set headline to (get value of IPTC tag "Headline" of theImg)
set AppleScript's text item delimiters to " "
set theTextItems to text items of headline
set AppleScript's text item delimiters to "-"
set headline to theTextItems as string
set AppleScript's text item delimiters to {""}
set objectName to (get value of IPTC tag "ObjectName" of theImg)
set newVersion to (headline & "-" & objectName) as string
set name of theImg to newVersion
end tell
end repeat
-- Exporting the files as JPEGs to chosen folder/Project Name using the Version Name as a filename
export theSel using export setting "JPEG - Original Size" to exportFolder
-- Resetting the Aperture Version Name back to filename using IPTC Title (which should be the file's filename without suffex).
repeat with theImg in theSel
tell theImg
set title to (get value of IPTC tag "ObjectName" of theImg)
set name of theImg to title
end tell
end repeat
end if
end tell
--Using ExifTool to set Photoshop Copyright Status etc
tell application "Finder" to set theFiles to files of exportFolder as alias list
repeat with eachFile in theFiles
do shell script "/usr/bin/exiftool -overwrite_original -Photoshop:CopyrightFlag='True' -Photoshop:URL='http://davidgordon.co.uk/'" & quoted form of POSIX path of eachFile
end repeat
display dialog "Done that!" with icon note buttons "OK" default button 1 giving up after 10 -
How to pass variables to shell script?
I have a shell script which uses the touch command to change the date of a file. To run the command on the command line the syntax is:
set-file-date.sh <file> <date>
I'm trying to run it from an automator workflow, so I'm prompted for the date, then the workflow iterates over the finder items, i.e., files, and changes the date of each files.
The problem is in the "Run Shell Script" action. The $@ is substituted with the file names selected in finder, so this will echo the file names:
for i in "$@"; do
echo "$i"
done
What I want to do is something like this:
for i in "$@"; do
set-file-date.sh <DATE VARIABLE> "$i"
done
But I can't prompt for the date value, and pass it to the script. I've tried using the "Get Value of Variable" and the "Ask For Text" actions. I can either get the file names from finder OR the text input in the "Ask for Text" action, but not both.
Is what I'm trying to do possible with a shell script?
-ThanksThis is standard AppleScript text concatenation...
set howManyWords to do shell script "wc -w /path/to/file | awk '{print $1}'"
do shell script "/usr/local/bin/growlnotify -t 'Corpus' -m '" & howManyWords & " words were added to the corpus.'"
in other words, just use the & to concatenate the parts of your text together. -
How to create database using shell script
hai
how to create database using shell scriptThe documentation details the steps to create a database manually. Another option is to use DBCA to create the scripts. DBCA will give you a complete set of scripts that will create a database.
http://download-east.oracle.com/docs/cd/B19306_01/server.102/b14231/create.htm#sthref220 -
How to Perform File- Place via Scripting (CS5)
Hi all,
Photoshop contains the option of directly placing one graphic file onto the currently active layer via the menu with File-> Place.
How do I do this in scripting?
TIA,
mlavie@xbytor2: Thanks for the quick response.
I noticed that File->Place does not bring the image's clipping path along with the image. Does your example do that, and if not, would you have any idea how?
TIA,
mlavie -
How to unzip files, how to unzip files
How do I unzip files on my mba 11 inch? I was told to use archive utilites but I can't find it.
I am having the same problem. I downloaded 5 Smilebox slideshows and downloaded the installer as instructed when I tried to open the files. None open, with DiskImageMounter and Disk Utility. Each time I get the installer instructions.
-
How to check from a shell script that a particular software is installed
Hai friends
I want to write a shell script which has to check whether a particular software is installed on the machine, or not. If installed, then what version is it using and the get the version number and which type of installer is it? i mean is it a .rpm installation or a tar.gz installation.
how can i check this from a shell script. If any of you have any idea please give me a sample script to check this
Thank you@Raja_Abilash
I don't think this is a right thread & right forum to POST this question.
better go ahead with forums related to LINUX.
Maybe you are looking for
-
I turned my iPod off last night and when I went to turn it back on, it got stuck on the logo. I tried to reboot it but it got stuck again. I waited about 15-20 minutes before rebooting it again. It got stuck once again. I plugged it into the computer
-
Problem with exception raised in UDM_GENWL
Exception "CNTRL ERROR" is raised when UDM_GENWL transaction code is to be executed in background. Please tell me how to correct that one.
-
Can IXOS (OPENTEXT) handle digitally signed PDF documents
Hi All, we have requirement where we want to store digitally signed PDF documents in IXOS (OPENTEXT) server and view them using IXOS viewer. I have tried to save one digitally sighed PDF but it was also password protected and I was not able to open
-
HOW CAN I PUT THE AMOUNT WITH THE SIGN OF DOLLAR?
HI! HOW CAN I PUT THE AMOUNT WITH THE SIGN OF DOLLAR? BECAUSE WHEN I WRITE THE DATA THE AMOUNT OVERWRITE THE SIGN. THANKS PEOPLE
-
Crystal Report Crosstab Page Number Issue
Hi Gurus, I am creating the crystal report which has variable column fields, so the number of pages are variable. The issue is, When i place the page number on the footer, It display only at the end of the page saying '1 of 1', I read lot of forums r