cron: Clock generating


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting cron: Clock generating
# 1  
Old 06-28-2013
cron: Clock generating

Hello.
I would like to do this :

A_VAR_FLAG = "ABCD" +------------+...................................+---------+
...............................|.................|...................................|.............|
...............................| ................|...................................|.............|
...............................| ................|...................................|.............|
A_VAR_FLAG = ""....... + ................+------------------------+............. +-------------------------------
cron call
a script . . . . . . . the script after
which set . . . . . . 5sec reset
A_VAR_FLAG . . . . A_VAR_FLAG
to "ABCD" . . . . . . to ""
-
-
A_VAR_FLAG must be visible to rsyslog ( service started during boot ).

rsyslog.conf contains this filtre :
Code:
 if $msg  contains getenv('A_VAR_FLAG') then

So depending the value of A_VAR_FLAG, $msg is kept or thrown away.

Any help is welcome.

Last edited by jim mcnamara; 06-28-2013 at 01:07 PM..
# 2  
Old 06-28-2013
You cannot change the environment of a procees that is running except from within. Have the parent export A_VAR_FLAG before calling rsyslog.
# 3  
Old 06-29-2013
Hello.
When rsyslog starts during boot ( or when it is restarted by hand ) , it read a config file which indicate some filter to use. And the filter syntax permit the use of environment variable as in my example "getenv('A_VAR_FLAG')" .

So do you mean that even if the global variable A_VAR_FLAG is created before rsyslog start, I have no way to change the point of view of rsyslog about the value of the variable A_VAR_FLAG ?
# 4  
Old 06-29-2013
Can you not:

1. create two environment variables A_VAR_FLAG='ABCD' and B_VAR_FLAG="" in the process when it starts. This part has nothing to do with config files, just the cron (or services startup ) script needs to have two lines:
Code:
export A_VAR_FLAG="ABCD"
export B_VAR_FLAG=""

2. have two separate rsyslogd.conf (or whatever name you use) files, one which specifies
Code:
getenv('A_VAR_FLAGS')

the other is identical except for
Code:
getenv('B_VAR_FLAGS')

3. create 2 files, something_A and something_B (you make up names).
something_A is the original startup. At startup:
Code:
cp something_A rsyslogd.conf
# code to start rsyslogd goes here
sleep 5
cp something_B rsyslogd.conf
pid=$(pgrep rsyslogd)
kill -HUP $pid # force rsyslogd to reread the config files

Basically I do not understand your requirement. At all. If you need to turn this filter on and off there are other more conventional ways to do it. Like stopping rsyslogd.

( I do not know the services command for your version but it amounts to this)
Code:
rsyslogd -f fileA
sleep 5
kill $(prgrep rsyslogd)
rsyslogd -f fileB

DGPickett is correct you cannot change a running process environment variables unless the process already has a direct means to change it. Specifically an IPC tool. Instead, you have to force the process to use another already existing variable, using a round about method. Or stop the process completely and recreate it with the right environment in the first place.

Last edited by jim mcnamara; 06-29-2013 at 08:06 PM..
# 5  
Old 07-01-2013
One easy IPC is to fetch the value from a file each loop A_VAR_FLAGS=$(<file), or source (.) a small config file like a short .profile that can be modiified, so any proc can rewrite the file and change the next pass.
# 6  
Old 07-09-2013
Stopping rsyslog is not the good way ( risk of loosing messages ).
I Know that I can use a file ( I use that often ) but rsyslog give function only to read environment variable.
# 7  
Old 07-10-2013
You can modify rsyslog to store this flag in a mmap()'d file, so you can modify that file on the fly -- no overhead, no interruptions, 1 additional page in working set.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Cron job scheduled is running once, but reports are generating twice

Team, Hope you all are doing fine I have one admin server which is being used dedicately to run cron jobs on hourly basis, fetching the details from Database which is in a different server.These cronjob are run on every hourly/5 minutes basis depending as per end user requirement.The script... (12 Replies)
Discussion started by: whizkidash
12 Replies

2. UNIX for Dummies Questions & Answers

Showing Clock

Is it possible to display the clock (timing) on the screen all the time. (3 Replies)
Discussion started by: vino.paal
3 Replies

3. Programming

problem with clock()

#include<iostream> #include<time.h> using namespace std; int main() { system("date"); clock_t start = clock(); int i=9*8; while(i--) { int j=9999999; while(j--); } clock_t end = clock(); double elapsed =... (4 Replies)
Discussion started by: johnbach
4 Replies

4. Shell Programming and Scripting

Sync Solaris System Clock With PDC Using Cron

Hi, I currently use the ntpdate and date command to sync the internal clock source of my Solaris systems to the primary domain controller. admin@myserver # ntpdate -d -u 192.168.???.??? 14 Jan 17:42:02 ntpdate: ntpdate 3-5.93e+sun 03/06/05 23:16:45 (1.4) transmit(192.168.???.???)... (2 Replies)
Discussion started by: jamba1
2 Replies

5. UNIX for Dummies Questions & Answers

Problems in generating the mail from cron -- very urgent help me

Hi, I wrote a script which generates a mail automatically under certain condition. When i execute the script manually in unix the script is getting executed and the condition works accordingly and the mail is also generated. But when it is pu into cron the mail is not generated and the... (4 Replies)
Discussion started by: thiru_cs
4 Replies

6. Solaris

Bugs with clock()

Hi there!!! Need your help in solving some tricky problems. Since clock() as such is buggy on SUN OS 5 we have started using gettimeofday() in our RTOS applications based on Solaris 9. The problems we actually encountered previously were - the applications kind of freeze/hang eternally on... (1 Reply)
Discussion started by: smanu
1 Replies

7. UNIX for Advanced & Expert Users

clock change

Hi We had a AIX box built last year but was set to the correct GMT time, but using DST time zone. In march this year the clocks went forward without issues. (if I remember a couple of weeks early due to the DST zone) This year we decided to change the clock to the correct time zone before... (0 Replies)
Discussion started by: markab2
0 Replies

8. Programming

clock() function

Hey all, i need a program to get the CPU ticks at certain points of my program. So, i thought about using the clock function, but i'm having a hard time figuring out how it really works. I wrote this simple program to try to understand it but it made me feel more confused: #include <stdio.h>... (5 Replies)
Discussion started by: kastrup_carioca
5 Replies

9. UNIX for Dummies Questions & Answers

Clock Trouble

Hey ppl, i was wonddering, in mandrake, how to get the clok to display the time in non-military format....hehe thank you im just tired of looking at 18:00 hehe thank you (2 Replies)
Discussion started by: LolapaloL
2 Replies
Login or Register to Ask a Question