Shell script for moving and renaming files
I'm not so familiar with shell scripts. I have created some simple scripts for various tasks but now I hit something I can't handle myself.
My server receives every night a logfile from another server. This file I need to rename and move to another location. Problem is that a simple mv with new filename isn't enough, I need to insert date in filename. Format for date should be ddmmyy. Also the name of incoming file changes every night. The output always starts with same letters, let's say "log", and the date is used to identify files.
For example I receive a file /Input/filename.log and I need to move the file to the folder /Output with name log130308.txt.
Any tips how to insert the date as part of of filename while renaming or moving the file? I prefer shell script as I'll use launchd for scheduling the script.
Hi again,
so far I've constructed this:
cd /input
for file in `ls *log`
do
echo "Copying " $file
cp $file /output/log.$file.`date +%d%m%y`
done
Quite there. I'm cding to directory, i'll focus later how to set some environmental parameters.
Problem with zipping is that I don't know exact logfiles names. Each day there's a new name. So zip -q filename.zip filename.log isn't quite enough and it's impossible to use wildcards. The switch -q and checksums were welcome suggestions.
Thanks again,
Juha
Message was edited by: J.Otava
Similar Messages
-
Shell Script for Startup and Shutdown the database
Hi,
i want Shell Script for Startup and Shutdown the database in Solaries.
could any one can hep me where i can get this script. or send to me to [email protected]
Thanks & Regards,
Gangi reddySHUTDOWN
SHUTDOWN ABORT]
Shuts down a currently running Oracle instance, optionally closing and dismounting a database.
Terms
Refer to the following list for a description of each term or clause:
ABORT
Proceeds with the fastest possible shutdown of the database without waiting for calls to complete or users to disconnect.
Uncommitted transactions are not rolled back. Client SQL statements currently being processed are terminated. All users currently connected to the database are implicitly disconnected and the next database startup will require instance recovery.
You must use this option if a background process terminates abnormally.
IMMEDIATE
Does not wait for current calls to complete or users to disconnect from the database.
Further connects are prohibited. The database is closed and dismounted. The instance is shutdown and no instance recovery is required on the next database startup.
NORMAL
NORMAL is the default option which waits for users to disconnect from the database.
Further connects are prohibited. The database is closed and dismounted. The instance is shutdown and no instance recovery is required on the next database startup.
TRANSACTIONAL [LOCAL]
Performs a planned shutdown of an instance while allowing active transactions to complete first. It prevents clients from losing work without requiring all users to log off.
No client can start a new transaction on this instance. Attempting to start a new transaction results in disconnection. After completion of all transactions, any client still connected to the instance is disconnected. Now the instance shuts down just as it would if a SHUTDOWN IMMEDIATE statement was submitted. The next startup of the database will not require any instance recovery procedures.
The LOCAL mode specifies a transactional shutdown on the local instance only, so that it only waits on local transactions to complete, not all transactions. This is useful, for example, for scheduled outage maintenance.
Usage
SHUTDOWN with no arguments is equivalent to SHUTDOWN NORMAL.
You must be connected to a database as SYSOPER, or SYSDBA. You cannot connect via a multi-threaded server. For more information about connecting to a database, see the CONNECT command earlier in this chapter.
http://download-west.oracle.com/docs/cd/B10501_01/server.920/a90842/ch13.htm#1013607
Joel Pérez -
[SOLVED] advanced shell script for mount and unmount samba share
Good morning guys,
Today I've a very long question....
Hope in your help....:
I usually move from different network.
For one of those I need to mount some share that are under an ActiveDirectory server.
To do that I use samba.
Especially I've made and use the below shell script.
I know that it's so stupid but I'm a very newbie:
#!/bin/sh
echo "This is a custom script for mount my citrix share"
echo "Please insert user password (must a sudoer user)"
echo " "
sudo mount -t cifs -o username='myusername',password='mypassword' //host_ip/TsHome$/myusername /home/myuser/samba_share/TsHOME
sudo mount -t cifs -o username='myusername',password='mypassword' "//host_ip/direction" /home/myuser/samba_share/direction
echo " "
read -p "Press ENTER key to close this terminal"
exit
As I say the script work but it's so crude...!
I want/need to implement it whit the follow addictions:
1. print a feedback on mount: somenthing like "TsHOME is now mounted" or "unable to mount TsHOME"
2. check if the share are already mounted: to prevent accidentally multiple mount. If a share is already mounted I want to print something like "TsHOME is already mounted on /home/myuser/samba_share/TsHOME"
3. ask for share password (now it's in clear on script) - This is optinal
4. un-mount the share before reboot or shutdown command. That because I've notice that If i reboot or shutdown without manually un-mount the share the step of unmounting network file system became very slow
If it's no extremely difficult, can someone help me to write this script?
I know that man exist but I'm not a programmer and it's so difficult for me approch it.
Thank you in advance.
Ale
Last edited by Alexbit (2010-09-23 21:29:13)Thank you very (VERY) much!
I've follow your information and.. it work!
If can be usefull to other this is the complete script:
#!/bin/sh
echo "This is a custom script for mount citrix share"
echo "****************************************"
echo " "
echo "Please insert domain password:"
read -s mypassword
echo " "
echo "|checking mount state...in share are not mounted mount it!|"
echo "+-------------------------------------------------------------------------+"
if grep "TsHome" /etc/mtab &>/dev/null; then
grep "TsHome" /etc/mtab | awk '{print "TsHome is already mounted on " $2}'
else
sudo mount -t cifs -o username='yourusername',password="$mypassword" //ipaddress/TsHome$ /home/Samba_share/TsHOME && echo "TsHOME is now mounted" || echo "unable to mount TsHOME"
fi
echo " "
if grep "direction" /etc/mtab &>/dev/null; then
grep "direction" /etc/mtab | awk '{print "direction is already mounted on " $2}'
else
sudo mount -t cifs -o username='yourusername',password="$mypassword" '//ipaddress/direction' /home/Samba_share/direction' && echo "direction pat is now mounted" || echo "unable to mount direction"
fi
echo " "
if grep "Area" /etc/mtab &>/dev/null; then
grep "Area" /etc/mtab | awk '{print "Area is already mounted on " $2}'
else
sudo mount -t cifs -o username='yourusername',password="$mypassword" '//ipaddress/Area' /home/Samba_share/Area && echo "Area is now mounted" || echo "unable to mount Area"
fi
echo " "
echo "All DONE!"
echo " "
read -p "Press ENTER key to close this terminal"
exit
I don't really well understand what I've to put in rc.local.shutdown....
I think somethings like:
#!/bin/bash
# /etc/rc.local.shutdown: Local shutdown script.
echo "This is a custom script for UN-mount citrix share"
echo "********************************************"
echo " "
echo "|check mount state: if mount then un-mount!|"
echo "+-------------------------------------------------------+"
echo " "
if grep "TsHome" /etc/mtab &>/dev/null; then
grep "TsHome" /etc/mtab | awk '{print "TsHome is NOT mounted -> going on..." $2}'
else
sudo umount /home/Samba_share/TsHOME && echo "TsHOME is now UN mounted" || echo "unable to UN-mount TsHOME"
fi
echo " "
if grep "direction" /etc/mtab &>/dev/null; then
grep "direction" /etc/mtab | awk '{print "direction is NOT mounted -> going on.." $2}'
else
sudo umount /home/Samba_share/direction && echo "direction is now UN mounted" || echo "unable to UN-mount direction pat"
fi
echo " "
if grep "Area" /etc/mtab &>/dev/null; then
grep "Area" /etc/mtab | awk '{print "Area is NOT mounted - Finished" $2}'
else
sudo umount /home/Samba_share/Area && echo "Area is now UN mounted" || echo "unable to UN-mount Area"
fi
echo " "
echo "going shutdown"
echo " "
sleep 5
I've try but it seems to ignore the IF statement... this is the output when ALL share are UNmounted:
$ sh /etc/rc.local.shutdown
This is a custom script for UN-mount citrix share
|check mount state: if mount then un-mount!|
+-------------------------------------------------------+
umount: /home/Samba_share/TsHOME: not mounted
unable to UN-mount TsHOME
umount: /home/Samba_share/direction: not mounted
unable to UN-mount direction
umount: /home/Samba_share/Area: not mounted
unable to UN-mount Area
going shutdown
Tomorrow I will test again when I'm at office.
Meanwhile can you check if I made a macroscopic mistakes?
Thank you again!
Last edited by Alexbit (2010-09-23 17:34:49) -
Shell script for export and import
Hi,
I want to run exp command in background since i need to export 40gb database of other database
if i won't use & my session will die.
appreciated any inputs.
i need to run this line from shell script.
/oracle/bin/exp pin@voipdbstg/pin file=voip.dmp owner=pin log=voip.log
bash-2.05$ more export.sh
#!/bin/sh
/oracle/bin/exp pin@voipdbstg/pin file=voip.dmp owner=pin log=voip.log
bash-2.05$ sh export.sh &
[10] 13352
bash-2.05$
Export: Release 8.1.7.0.0 - Production on Fri Dec 4 22:51:09 2009
(c) Copyright 2000 Oracle Corporation. All rights reserved.
Password: pin
bash: pin: command not found
[10]+ Stopped sh export.sh
input appreciated
thanks
PrakashHi,
/oracle/bin/exp pin@voipdbstg/pin file=voip.dmp owner=pin log=voip.log
should be
/oracle/bin/exp pin/pin@voipdbstg file=voip.dmp owner=pin log=voip.log
Also for running the script is background and you should be able to log out of shell scriptthen run the command in nohup mode.
$nohup export.sh&
Regards -
Shell script for oracle alert.log file
Hi Gurus,
I wanted to write shell script to know the last 10 shutdown timings of the database from alert log file. I'm working on oracle 9i.
Could anyone please advice on this.
Thanks in advance
regards,
Shaan
Edited by: Shaan_dmp on Jan 5, 2009 1:27 PM
Edited by: Shaan_dmp on Jan 5, 2009 1:28 PMUse awk. I don't have a 9i to hand but here is a very simple version for 10g XE
My awk file (the line numbers are for the notes below - don't include them:
01:BEGIN { prevline = "";}
02:
03:/Completed: alter database close/ {print prevline,FS,$0;}
04:
05:{prevline = $0;}The command line and results (from my 300k alert log)
$ awk -f alert.awk.txt alert_xe.log
Fri Apr 11 18:08:40 2008 Completed: alter database close normal
Fri May 16 18:53:21 2008 Completed: alter database close normal
Tue May 20 17:28:23 2008 Completed: alter database close normal
Thu Jul 17 19:08:52 2008 Completed: alter database close normal
Fri Aug 15 15:12:48 2008 Completed: alter database close normal
Wed Nov 05 08:52:59 2008 Completed: alter database close normal
Fri Nov 14 16:36:03 2008 Completed: alter database close normal
Tue Dec 09 10:46:23 2008 Completed: alter database close normal
Mon Jan 05 11:12:22 2009 Completed: alter database close normalWhat it means:
1) the BEGIN section at line 01 defines the variable to hold the previous line
2) the /search string/ at line 03 finds the marker in the file for a shutdown, then does the required action (print the time which was in the previous line, and then this line; use FS (the awk field separator - normally space) as a separator
3) at line 05 is an instruction we do on every line - so we remember it in case it is the timestamp for the shutdown.
Now, you can include more of the corner cases for shutdowns by adding more search patterns etc. For more information, google for awk examples.
Awk is really good at this sort of thing!
HTH
Regards Nigel -
Shell Script For Export And Import Of Table Records
Hello,
We have production and test instances and for constant testing we need to copy data from production to test or development environment.
At the moment what we do is manually doing export and import table records. At times this could be very tedious as we may need
to do this exercise a couple of times in a day.
Is it a good idea to do this exercise using shell script? If so how could I do this? If this is not a good idea what are the best alternatives?
Any input is highly appreciated.
ThanksAh I see, your company prefers stupidity over efficiency. It would be possible to do it in a controlled environment, wouldn't it? Also the test database would be allowed to select only.
So the non-allowance is just plain stupid.
To the second question: do you use hard-coded passwords in shell scripts?
Don't you think that poses a security risk?
Don't you think that is a bigger risk than a database link, properly set up?
In my book it is!
Sybrand Bakker
Senior Oracle DBA -
Moving and renaming files after PSE has uploaded them
I use PSE 7
I have many folders (50+) and perhsps file names ( few thousdand) that after uplaoding all of them into PSE and tagging about half I am consdering remaning some of them and also combine some folders or just renaming some folders
any way to do this with in PSE by jsut doing a folder at a time ( change folder name) and change file names all at once.
Would it be easyer to start all over by deleting all images in PSE but not on the disk then reload it all, will the tags still show up on the photo AND all the tags icons on the side bar be their after
any help greatly appreacted, I should have done this before starting to work in PSE
thanks
MikeI think the biggest thing people miss understand about the Organizer is you no longer have to be concerned with folders or where the photos are located. The beauty of Tags allows you to locate your photo by various methods that you can not do with folders. You can have a tags for location, event and peoples name on the same photo and you can locate it in your Organizer catalog by selecting any combination of the tags you have assigned. You can not do that with folders. As an example you can find a photo of Jane, from California, at your graduation party.
Adobe does a poor job of highlighting the advantages of creating tags. The original creator of Album that was later changed to Organizer, Michael Slater, wrote a book on how and what you should think about before creating tags. Unfortunately, he no longer works for Adobe and the book was written for PSE 3. And a lot has changed since then. But the basic concept of using tags verses folders is still applicable and the Chapter is and well worth the price of the book which is still available from Amazon. http://www.amazon.com/Organize-Photos-Adobe-Photoshop-Elements/dp/0321246969 -
Shell script for calling an sql file
Hello, I would need your help in creating a ksh file. We have two ksh files. One for deletion the eim table and the other one is for running the eim job.
Ksh file for running the eim job is okay. But the ksh file running the delete sql is not. We were thinking that we may have some sort of mistake in the syntax could have caused the problem we experiencing now. Need your expertise to check it. Please?
Here’s the syntax we have.
#!/bin/sh
sqlplus -s <user>/<pwd>@dbname << EOF
@<folder-path>/sqlrun.sql
EXIT
ENDSQL
EXIT
When we run it against putty, nothing seems to happen as in no error message appears at all. It prove that the sql file did not execute in TOAD.
We tried the other way around, by putting the /dev/nu// as show below.
sqlplus -s <user>/<password>@DBNAME > /dev/null <<ENDOFSQL
still nothing happen.
Regardsuser10070712 wrote:
Hello, I would need your help in creating a ksh file. We have two ksh files. One for deletion the eim table and the other one is for running the eim job.
Ksh file for running the eim job is okay. But the ksh file running the delete sql is not. We were thinking that we may have some sort of mistake in the syntax could have caused the problem we experiencing now. Need your expertise to check it. Please?What does this have to do with APEX, which is the topic of this forum?
What is "eim"? Why have you chosen to post this here? -
Need script for moving files to specific directories base on csv
Hi,
I have a question. I have about 2000 files (pdf), which I need move to specific directories and subdirectories, which are based on csv file.
Csv is looking like this:
filename;directoryname;subdirectoryname;subdirectoryname;.......etc.
I have a script for creating directories with subdirectories from csv file, but I need this script for moving files to this directories.....
Thanks a lot for every help.
Best Regards
Petr, OS X Mavericksprivate function snapshotLastFrame():void
gotoAndStop( this.totalFrames );
_bitmapData = new BitmapData( stage.stageWidth, stage.stageHeight );
_bitmap = new Bitmap( _bitmapData );
_bitmapData.draw ( stage );
saveImageJPG( _bitmapData, "test.jpg", 96 );
public function saveImageJPG( bitmapData:BitmapData, fileName:String, quality:int ):void {
this.jpgEncoder = new JPGEncoder( quality );
this.fileReference = new FileReference();
this.fileReference.save( this.jpgEncoder.encode( bitmapData ), fileName + ".jpg" );
Keep in mind that you need a few extra libraries to be able to create a jpeg.. (AS3CoreLib) can be found at googleCode. -
Need Shell Script for picking the files
Hi,
I want to write a shell script for piking the files in a sequence order (according to filename with time stamp) from the sorce FTP server ..
Requirement is in the source directory I'm getting files (Jain_1.xml , Jjain_2.xml, Jain_3.xml .. ect..) at present my file adapter is picking all the files at a time but i want to pick one by one... that to first i want to Jain_1.xml after finish the processing of the file then only my file adapter should pick the next file ( Jain_2.xml ) .
so.. all the forum mates suggest me to write a shell script.. but where i have to write the s hell script. and where i have to deploy this script.... my Xi is running on UNIX ... so please sugest me the procedure ...
Regards
JainHi,
Why dont you use the option EOIO in which files will be picked up in order and will be proccessed in sequence....one after another....
Regards,
Sreeni. -
Wireless network (and a shell script for you guys, also)
I don't know the right way to bring up my wireless iface at bootup, so I wrote a small shell script to do it for me.
Feel free to use it if you find it useful..
I'd also appreciate someone telling me what *IS* the arch way of doing what my shell script's doing
#!/usr/bin/env bash
# Val Polyakov <[email protected]>
# 7/8/07
# Change these to reflect your network
PATH=/usr/sbin:/sbin:/bin
IFACE=ifaceNameOfYourWirelessCard
DRIVER=moduleNameForYourWirelessCard
SID=yourSID
ENCKEY=yourEncryptionKey
# Don't change anything beyond this point.
case "$1" in
start)
echo "Loading the wireless card driver"
modprobe $DRIVER
echo "Setting up the SID and encryption key"
iwconfig $IFACE essid $SID enc $ENCKEY
echo "Bringing up the wireless interface"
ifconfig $IFACE up
if [ -f /var/run/dhcpcd-$IFACE.pid ]
then
rm /var/run/dhcpcd-$IFACE.pid
fi
echo "Running the dhcp client"
dhcpcd $IFACE
stop)
echo "Bringing down the wireless interface"
ifconfig $IFACE down
echo "Unloading the driver"
rmmod $DRIVER
restart)
$0 stop
sleep 2
$0 start
echo "usage: $0 {start|stop|restart}"
esac
exit 0brain0 wrote:If your wireless drivers support wpa_supplicant, you could try autowifi from http://www.archlinux.org/~thomas/autowifi-svn/ It handles multiple wireless networks very well. There is no documentation right now, just read here: http://archlinux.org/pipermail/arch-dev … 00867.html
what would the benefit of that be, as compared to my script ?
the shell script i made (and pasted) works just fine, sits in /etc/rc.d and is called by /etc/rc.conf
i was just curious whats the official, i guess, way to do it with arch
since network profiles dont work for some reason, i figured i must be missing something.. -
Want to create unix shell script for Clone procedure in 11i and r12
Want to create unix shell script for Clone procedure in 11i and r12 .Can anyone help me on this as I m new to oracle apps and scripting.
Thanks in advance .user11958935 wrote:
Thanks but I want it for application cloning ie adcfgclone and autoconfig etc .Please see old threads for similar topic/discussion.
https://forums.oracle.com/forums/search.jspa?threadID=&q=Automate+AND+Rapid+AND+Clone&objID=c3&dateRange=all&userID=&numResults=15&rankBy=10001
https://forums.oracle.com/forums/search.jspa?threadID=&q=Automate+AND+AutoConfig&objID=c3&dateRange=all&userID=&numResults=15&rankBy=10001
Thanks,
Hussein -
About shell scripts for large-scale automation of encoding tasks
in the user menu of Compressor, it said that we can use the command line to write shell scripts for large-scale automation of encoding tasks.
I would like to have more information about the shell script for compressor, is that any document link?
ThanksYou can use a script function to set-up a more secure environment that you call at the start of every admin script. This could be your main stamp album for stuff that can be moved there.
A few more stamps to add to the collection (be sure to read up on them before use):
1) reset the command hash
hash -r
2) prevent core dumps
ulimit -H -c0
3) set the IFS
4) clear all aliases (see unalias -a)
Also you can remove the ALL from sudo and add explicit commands to the the sudoers file. There's a lot of fine tuning you can do in sudoers - inc. env variables as teekay said.
But I'm no expert so best to check all of the above. -
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 -
Shell script for archive log transfer
hi
I dont want to reinvent the wheel.
I am looking for shell script for log shipping to provide standby db.
What I want to do is, get the last applied archived log number from alert.log
Copy the files from archive destination according to this value.
CheersIf you don't want to re-invent the wheel you use Dataguard, no scripts.
And your script should use the dictionary, instead of some bs method to read the alert.
v$archived_log has all information!
Also as far as I know, the documentation describes manual standby.
So apparently you not only don't want to reinvent the wheel, but you want the script on a silver plate on your doorstep!
Typical attitude of most DBAs here. Use OTN for a permanent vacation.
Sybrand Bakker
Senior Oracle DBA
Maybe you are looking for
-
Not able to print on Purchase order whatever we fill in item text
not able to print on Purchase order whatever we fill in item text, from where can we link to get printed item text on purchase order
-
Just picked up a Sony NEX-C3, got it home only to find that iPhoto'11, Aperture 3 and OSX 10.7 doesn;t support the ARW RAW format it uses. I know this camera is relatively new to the market (2-3 weeks old), but how long should I expect to see Apple u
-
Extra column names selected when using the 'popup describe' for selecting columns
Hi, In SQL Developer 3.2.20.09, if you use the popup describe function on a table and individually select some columns using Ctrl + click (not shift click which would select a range of columns), and then drag them to the SQL worksheet so the column n
-
Exchange Server 2013 to 2010 mailbox proxy is not working
I have exchange server 2013 and exchange server 2010 in co-exist. I have 3 cas server and 3 mbx server 2013 on windows server 2012 standard, 2 hub/cas server and 2 mbx server 2010 on windows server 2008 r2. when I try to access owa of exchange server
-
Conditions on Calc/Restricted KFs
Hi EXPERTS, Can conditions work on restricted and calculated key figures in a query? Thanks Hemant