How to preserve the value of a variable from being overwritten?
Hi All,
I am new new to unix.com, I have a question related to shell scripting.
We have a Oracle database backup shell script, which can be used for taking full, incremental & archive log backup based on the parameters passed.
Within the script we export a variable as
So for every execution of backup, we will have a unique gv_shell_id. We store the gv_shell_id along with other backup details in a database table for reporting purpose.
If we have executed a full backup, it will set a gv_shell_id and if simultaneously some one kicks off archive log backup, it will reset the gv_shell_id with different value.
And this is causing a wrong entry of gv_shell_id for full backup in the table.
Basically i want to make the variable itself unique for every execution to avoid such problem.
I tried using gv_shell_id_$$=$(date "+%y%m%d_%H%M%S_")$$
but it throws below error.
Can you please help me in generating a unique variable so that it doesn't get overwirtten by any other execution of same script.
Last edited by Scott; 07-12-2014 at 09:37 AM..
Reason: Please use code tags
I'm missing something very basic here. The command:
will assign a distinct value to gv_shell_id each time your backup script is invoked.
Why isn't your backup script initiating the appropriate type of backup and writing the results of that backup into your database using the value of gv_shell_id it assigned? What is getting confused and writing the wrong value of gv_shell_id into your database?
I can only emphasize what Don Cragun has already said. You didn't post your script therefore, instead of offering detailed advice, i will only make some general remarks. You are invited to post your complete script if you want to get better and more specific help.
Quote:
Originally Posted by veeresh_15
I am new new to unix.com, I have a question related to shell scripting.
We have a Oracle database backup shell script, which can be used for taking full, incremental & archive log backup based on the parameters passed.
Within the script we export a variable as
So for every execution of backup, we will have a unique gv_shell_id. We store the gv_shell_id along with other backup details in a database table for reporting purpose.
I think we have here a (common) misunderstanding about what "export" does, so let us address that first.
Every process has its own set of variables (and their respective values), which form the so-called "process environment". Processes form hierarchies, where one process (the "child process") is called by the other (the "parent process") and it would be good to have a mechanism which passes the process environment of the parent on to the child.
Exactly this does the "export" keyword. Issuing an "export <variablename>" flags the variable to be inherited by an eventual child process if one is invoked. As long as you stay inside the process there is no difference. You also do not need to "export" the variable again if its value changes. A variable is either "marked for being inherited by the child process" or it is not, but the inheritance takes place at the time the child process starts and with the value the exported variable has by then.
Quote:
Originally Posted by veeresh_15
If we have executed a full backup, it will set a gv_shell_id and if simultaneously some one kicks off archive log backup, it will reset the gv_shell_id with different value.
No. If your script is called twice these two will be (maybe simultaneously running) instances, which will - from an OS point of view - not interfere with each other. They will have two separate environments and will run alongside each other.
Of course, just because they are indenpendent in the eyes of the operating system that doesn't mean they couldn't interfere at all. If they use the same resources - they probably issue commands against the same database, which will cause the DB to change its state - they can cause problems for each other. But this has nothing to do with their process environments, but rather with a competition for common resources, where the "common resource" in this case is the database or some vital part of it.
My suggestion is to make sure the script is executed only once at a time. Usually you do this by creating a PID-file at the begin of the script and removing it at the end. See the following sketch:
Depending on your shell you may put the removal of the PID file into a service routine for "trap 0", which will enhance the runtime security, but not change the basic, underlying logic.
thanks alot bakunin for such a detailed expalination on process variables. It really cleared my doubts.
Regarding my original problem statement,i will get back to you guys after doing somemore homework.
Thank you everyone for trying to resolve my issue.
I had generated a ssh2 key on my AIX box, to receive files from other AIX and Linux systems.
Key Name: id_ssh2_server.pub
However this ssh2 key (both public and private keys) has been overwritten, while I was generating another ssh2 key. Now the earlier configured target systems are not able... (3 Replies)
Hello,
I wondering how I can echo a string without having the trailing whitespace removed.
For example I have a string str="TESTING123 " that I need to hash using sha1. I get the correct answer when I run the line below from the terminal
$ echo -n "TESTING123 " | openssl sha1... (3 Replies)
This seems to be a stupid basic question, but I cant get the space to stick in the awk variable.
I do use this command to grep a time range of the log file.
cat /var/log/daemon.log | awk '$0>=from&&$0<=to' from="$(date +%b" "%e" "%H:%M:%S -d -24hour)" to="$(date +%b" "%e" "%H:%M:%S)"
I now... (9 Replies)
Hello All,
I am writing a bash script on Solaris O/S. I looping through an array. For each iteration, i connect to the datatabase and use select statement. Output of which is redirected to .CSV file. here is the code for it.
output="loop.csv"
elements=${#currency_pair}
... (3 Replies)
Hi, i have some problems with the following code:
char *tab_path;
char *sep=" \t\n";
char line;
char *p;
FILE * file;
int i = 0;
if(fgets(line,MAXLINE,file)!=NULL){
if((p=strtok(line,sep))!=NULL)tab_path=p;
while((p=strtok(NULL,sep))!=NULL){
i++;
... (4 Replies)
Hi,
The dump device on my system was set to /dev/dsk/c0t0d0s7. I have done a savecore -Lv on the system which worked fine. I'm wondering have I overwritten the rootdisk here by mistake? The system is still up but will need to be rebooted due to an error on it. Will it come back up?
... (8 Replies)
The following files were wiped out - new empty files were left in their place.
/etc/inittab, /etc/inetd.conf, and /etc/MANPATH
The system is running HP-UX 11i v3 - Mar08.
Anyone seen anything like this?
Any ideas on a way to figure this out if it happens again or a suggested way to... (9 Replies)
We have a problem where we delete a user and their associated UID gets dumped back in the UID pool. The if we immediately create a another (new) user, AIX reuses the last UID, the one that was just released. This is causing a problem when reports are being generated because the new users name is... (2 Replies)
Hello,
One of my frend had a problem.
He had Windows XP installed on his system. Then he installed Red Hat Linux 8.0 in one of the partitions. After some time his XP got corrupt and then he reinstalled Windows XP. This over wrote the Grub loader entry, and due to this the grub loader is not... (2 Replies)
Hi, My account is : abcd
I belong to a group: pqrs
Some thing straneg happened yesterday.
My .cshrc and .login got overwritten into pqrs's .cshrc and .login
I obviously did not explicitly overwrite pqrs's .cshrc.
Are there any reasons how this could have happened indirectly due to... (5 Replies)