Tag Archives: DAY

How to convert FORTRAN subroutine to awk function?

By Akshay Hegde

Hi All I am trying to convert following subroutine to awk function , those who know kindly help, I want to learn about awk user defined function

Code:

JD -- > JULIAN DATE


Code:

SUBROUTINE GDATE (JD, YEAR,MONTH,DAY)
C
C---COMPUTES THE GREGORIAN CALENDAR DATE (YEAR,MONTH,DAY)
C GIVEN THE JULIAN DATE (JD).
C

INTEGER JD,YEAR,MONTH,DAY,I,J,K
C
L= JD+68569
N= 4*L/146097
L= L-(146097*N+3)/4
I= 4000*(L+1)/1461001
L= L-1461*I/4+31
J= 80*L/2447
K= L-2447*J/80
L= J/11
J= J+2-12*L
I= 100*(N-49)+I+L
C
YEAR= I
MONTH= J
DAY= K
C
RETURN
END


Code:

number to be inputted is JD


Code:

Example: YEAR = 1970, MONTH = 1, DAY = 1, JD = 2440588.
Gregorian date for Julian date[JD] 2440588 is 01/01/1970


…read more

Source: FULL ARTICLE at The UNIX and Linux Forums

Backups using rsync

By dpatino

Hello all,

I’m using nas4free as a SAN and am having troubles getting a backup of it’s data to work properly. I’ve posted in the nas4free forums, but haven’t received much help.

Here is the code I’m using:

Code:

#!/bin/sh
{
#########################################################################################
# File: casedatabackup.sh
# Author: Daryl Patino
# Date: 03-18-2013
# Purpose: Daily incremental backups and weekly archive of backups using rsync
#
#
# Important Usage Notes:
# -cp this file with a different name to retain this file as a template
# -edit logfilename located in BODY variable and end of script to match share
# -view existing scripts for examples
# -end all directory variables with /
# -must run the following command on the file "chmod u+x /path/file"
#########################################################################################

#########################################################################################
# Constant variables, do not change
#########################################################################################

DAY=$(date +%A)
DATE=$(date +%m_%d_%y)
PRINTF=/usr/bin/printf
MSMTP=/usr/local/bin/msmtp
MSMTPCONF=/var/etc/msmtp.conf

#########################################################################################
# Dynamic variables, changeable
#########################################################################################

# Mail settings
FROM="nas4free@usinfosec.com"
TO="helpdesk@usinfosec.com"
MDIR="CaseData"
SUBJECT="$MDIR Backup Report"
BODY="$(cat /mnt/support/logs/casedata.log)"

# Sync settings
RSOURCE="/mnt/POOL/CaseData/"
RDEST="/mnt/syl-s-012/Backups/CaseData/Daily/"
ASOURCE=$RDEST
ADEST="/mnt/syl-s-012/Backups/CaseData/Weekly/"

#########################################################################################
# Backup operations
#########################################################################################

# Daily file sync
rsync -a --stats $RSOURCE $RDEST

# Weekly archive and follow up sync to remove deleted files
if [ $day = "Sunday" ]; then
tar -zcf $ADEST$DATE.tar.gz $ASOURCE
rsync -a --delete --stats $RSOURCE $RDEST
find $ADEST -mtime +14 -exec rm {} ;
fi

# Sends email of log file
$PRINTF "From:$FROMnTo:$TOnSubject:$SUBJECTnn$BODY" | $MSMTP --file=$MSMTPCONF -t

} > /mnt/support/logs/casedata.log


It is scheduled to run as a cron once per day via the nas4free gui. The script runs, and the daily rsync works, but the log file is empty and the weekly commands (in the if statement) do not seem to be working. When I run the tar individually, I get the following:

Quote:

syl-s-030:~# tar -zcfv /mnt/syl-s-012/Backups/CaseData/Weekly/date.tar.gz /mnt/syl-s-012/Backups/CaseData/Daily/
tar: Removing leading ‘/’ from member names

/: write failed, filesystem is full
tar: Write error


I know that the embedded nas4free doesn’t have room to install any additional applications, but the source and destination are mounted shares.

So my questions are this.

Does tar use some kind of temp directory that is local? If so, can it be changed?

My logging syntax might be incorrect. If so, how can I create a log of the scripts output that can be emailed?

…read more
Source: FULL ARTICLE at The UNIX and Linux Forums

Backups using rsyn

By dpatino

Hello all,

I’m using nas4free as a SAN and am having troubles getting a backup of it’s data to work properly. I’ve posted in the nas4free forums, but haven’t received much help.

Here is the code I’m using:

Code:

#!/bin/sh
{
#########################################################################################
# File: casedatabackup.sh
# Author: Daryl Patino
# Date: 03-18-2013
# Purpose: Daily incremental backups and weekly archive of backups using rsync
#
#
# Important Usage Notes:
# -cp this file with a different name to retain this file as a template
# -edit logfilename located in BODY variable and end of script to match share
# -view existing scripts for examples
# -end all directory variables with /
# -must run the following command on the file "chmod u+x /path/file"
#########################################################################################

#########################################################################################
# Constant variables, do not change
#########################################################################################

DAY=$(date +%A)
DATE=$(date +%m_%d_%y)
PRINTF=/usr/bin/printf
MSMTP=/usr/local/bin/msmtp
MSMTPCONF=/var/etc/msmtp.conf

#########################################################################################
# Dynamic variables, changeable
#########################################################################################

# Mail settings
FROM="nas4free@usinfosec.com"
TO="helpdesk@usinfosec.com"
MDIR="CaseData"
SUBJECT="$MDIR Backup Report"
BODY="$(cat /mnt/support/logs/casedata.log)"

# Sync settings
RSOURCE="/mnt/POOL/CaseData/"
RDEST="/mnt/syl-s-012/Backups/CaseData/Daily/"
ASOURCE=$RDEST
ADEST="/mnt/syl-s-012/Backups/CaseData/Weekly/"

#########################################################################################
# Backup operations
#########################################################################################

# Daily file sync
rsync -a --stats $RSOURCE $RDEST

# Weekly archive and follow up sync to remove deleted files
if [ $day = "Sunday" ]; then
tar -zcf $ADEST$DATE.tar.gz $ASOURCE
rsync -a --delete --stats $RSOURCE $RDEST
find $ADEST -mtime +14 -exec rm {} ;
fi

# Sends email of log file
$PRINTF "From:$FROMnTo:$TOnSubject:$SUBJECTnn$BODY" | $MSMTP --file=$MSMTPCONF -t

} > /mnt/support/logs/casedata.log


It is scheduled to run as a cron once per day via the nas4free gui. The script runs, and the daily rsync works, but the log file is empty and the weekly commands (in the if statement) do not seem to be working. When I run the tar individually, I get the following:

Quote:

syl-s-030:~# tar -zcfv /mnt/syl-s-012/Backups/CaseData/Weekly/date.tar.gz /mnt/syl-s-012/Backups/CaseData/Daily/
tar: Removing leading ‘/’ from member names

/: write failed, filesystem is full
tar: Write error


I know that the embedded nas4free doesn’t have room to install any additional applications, but the source and destination are mounted shares.

So my questions are this.

Does tar use some kind of temp directory that is local? If so, can it be changed?

My logging syntax might be incorrect. If so, how can I create a log of the scripts output that can be emailed?

…read more
Source: FULL ARTICLE at The UNIX and Linux Forums

Utilities not dying after script run

By Marc G

Hi folks,

Friendly router geek wanting to be a programmer here…

So I worked with another guy here and came up with this to capture Unix admin data:

Code:

#!/bin/ksh
#
#
# Set Default Paths
#
PATH=/usr/apps/client/bin:$PATH; export PATH
LD_LIBRARY_PATH=/usr/apps/client/lib:$LD_LIBRARY_PATH; export LD_LIBRARY_PATH
NOSHOME=/usr/apps/client/bin; export NOSHOME

# Execute the NOS provided top program with CPU MEMORY and LOAD values to be extracted to temporary files
#
$NOSHOME/top -d1 -q | /usr/bin/head -n 5 | /usr/bin/grep CPU | /usr/bin/awk -F"," '{print $1}' | /usr/bin/awk -F":" '{print $2}' | /usr/bin/awk -F" " '{print $1}' > /tmp/cpu.out
$NOSHOME/top -d1 -q | /usr/bin/head -n 5 | /usr/bin/grep Memory | /usr/bin/awk -F"," '{print $1,$2}' | /usr/bin/awk -F":" '{print $2}' | /usr/bin/awk -F" " '{print $1","$4}' > /tmp/mem.out
$NOSHOME/top -d1 -q | /usr/bin/head -n 5 | /usr/bin/grep Memory | /usr/bin/awk -F"," '{print $3,$4}' | /usr/bin/awk -F" " '{print $1","$4}' > /tmp/swap.out
$NOSHOME/top -d1 -q | /usr/bin/head -n 5 | /usr/bin/grep load | /usr/bin/awk -F";" '{print $2}' | /usr/bin/awk -F":" '{print $2}' | /usr/bin/sed 's/^[ ]*//;s/[ ]*$//' > /tmp/loadavg.out

# Gather all data into single file and clean up
#
CPU=`cat /tmp/cpu.out`
MEM=`cat /tmp/mem.out`
SWAP=`cat /tmp/swap.out`
LOAD=`cat /tmp/loadavg.out`
HOST=`/usr/bin/hostname`
DAY=`/usr/bin/date +%b-%d-%y`
TIME=`/usr/bin/date +%H:%M:%S`

# Configure date values to figure out proper storage of comma delimited values
#
typeset -i MONTH=`/usr/bin/date +%m`
MONTH=$(echo "$MONTH" | tr ' ')
typeset -i DAY=`/usr/bin/date +%d`
DAY=$(echo "$DAY" | tr ' ')
typeset -i YEAR=`/usr/bin/date +%Y`
YEAR=$(echo "$YEAR" | tr ' ')

# Create a variable FILE to concat variables into a single variable to test against
FILE=$MONTH"-"$YEAR-$HOST".dat"

# Check to see if file is empty. If not, populate the values, otherwise create the needed file and populate
#
if [ -e $NOSHOME/../data/OSKPI/$FILE ]
then
echo $HOST","$DAY","$TIME","$CPU","$MEM","$SWAP","$LOAD >> $NOSHOME/../data/OSKPI/$MONTH-$YEAR-$HOST.dat
else
echo $HOST","$DAY","$TIME","$CPU","$MEM","$SWAP","$LOAD > $NOSHOME/../data/OSKPI/$MONTH-$YEAR-$HOST.dat
fi

# Remove all temporary files and exit
#
rm /tmp/cpu.out /tmp/mem.out /tmp/swap.out /tmp/loadavg.out
exit 0


But once the script runs, it leaves processes still running as shown:

Code:

bash-3.00$ ps -efa | grep -v wrapper | grep -v oracle | grep -v java
.
.

.
root 11153 11098 0 07:00:04 ? 0:00 /usr/bin/sed s/^[ ]*//;s/[ ]*$//
root 19606 479 0 00:14:49 ? 0:00 /usr/lib/ssh/sshd
<font ...read more
Source: FULL ARTICLE at The UNIX and Linux Forums

Can't see what I'm doing wrong

By Marc G

In: # pwd
/usr/apps/vender/data/OSKPI

I have:ls | grep 2013
-rw-r–r– 1 root root 70 Feb 11 11:53 2-2013.dat

My code wants to either append or write new:


typeset -i MONTH=`date +%m`
MONTH=$(echo "$MONTH" | tr ' ')
typeset -i DAY=`date +%d`
DAY=$(echo "$DAY" | tr ' ')
typeset -i YEAR=`date +%Y`
YEAR=$(echo "$YEAR" | tr ' ')

FILE=$MONTH"-"$YEAR".dat"

if [-e /usr/apps/vender/data/OSKPI/$FILE]
then
echo $HOST","$DAY","$TIME","$CPU","$MEM","$SWAP","$LOAD >> /usr/apps/vender/data/OSKPI/$MONTH-$YEAR.dat
echo "I did branch one"
else
echo $HOST","$DAY","$TIME","$CPU","$MEM","$SWAP","$LOAD > /usr/apps/vender/data/OSKPI/$MONTH-$YEAR.dat
echo "I did branch two"
fi
printf "n" >> /usr/apps/vender/data/OSKPI/$MONTH-$YEAR.dat


No matter if I use -e or -f, the if statement does not see the existing file and does the “else”..

Can anyone tell me what I’m doing wrong?

Thanks,

Marc

…read more
Source: FULL ARTICLE at The UNIX and Linux Forums