Sponsored Content
Top Forums Shell Programming and Scripting Howto shorten script in a busybox environment by using for loops? Post 302399273 by Nila on Saturday 27th of February 2010 12:09:36 AM
Old 02-27-2010
Sorry.There is some problem in interpolation of the variables.

Now,I corrected those errors.You check the following code.

Code:
day=`date +"%Y%m%d"`
month=`date +"%m"`
year=`date +"%Y"`

days_in_month()                # maximum days of every month
{
  case $month in
    09|04|06|11) maxdays=30 ;;
    01|03|05|07|08|10|12) maxdays=31 ;;
    02) if (( ("$year" % 400) == "0" )) || (( ("$year" % 4 == "0") && ("$year" % 100 != "0") )) ; then
          maxdays=29
        else
          maxdays=28
       fi
  esac
}

check_end_of_month_year()        # check if it will be end of month/year
{
  if [ $day_temp -gt $maxdays ]; then # reached end of month
    day_temp=01
    month=$[$month+1]
    if [ $month -gt 12 ]; then       # reached and of year
      month=1
      year=$[$year+1]
    fi
    new_month=yes            #
    days_in_month            # calculate max days in new month
  fi
  month=`printf "%02d" $month`
}

days_in_month                   # how many days does current month have
new_month=no                  # parameter to indicate new month or not
day[0]=`date +"%e"`            # put date of today in day0
FILE0=$day"_US.gif"            # real filename for FILE0 download

# ######################################
# ------- I think the source below can be smaller -------
# ######################################

j=1
for((i=0;i<5;i++))
do
let day[$j]=$[${day[$i]}+1]
let j=j+1
done

for((i=1;i<6;i++))
do
if [ $new_month = yes ]; then
  day_temp=$[$day_temp+1]        # day_temp will be used in check_end_of_month_year
else
  day_temp=${day[$i]}
fi
check_end_of_month_year            # check if it will be end of month/year
day[$i]=`printf "%02d" $day_temp`        # day1 = daytemp but with leading zero

#echo ${day[$i]}

if [[ $i -eq 1 ]];then
FILE1=$year$month${day[$i]}"_US.gif"        # real filename for FILE1 download
#echo $FILE1
elif [[ $i -eq 2 ]];then
FILE2=$year$month${day[$i]}"_US.gif"        # real filename for FILE1 download
#echo $FILE2
elif [[ $i -eq 3 ]];then
FILE3=$year$month${day[$i]}"_US.gif"        # real filename for FILE1 download
#echo $FILE3
elif [[ $i -eq 4 ]];then
FILE4=$year$month${day[$i]}"_US.gif"        # real filename for FILE1 download
#echo $FILE4
elif [[ $i -eq 5 ]];then
FILE5=$year$month${day[$i]}"_US.gif"        # real filename for FILE1 download
#echo $FILE5
fi
done

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Howto read data into a shell script

Hi all, I'm anew shell user, and want to now how to do that? i have a files that have inside few raws of names of directories, i want to read only the lins that are a dir name how to do so. the file looks like that #################################### # This is the list of dirs files ... (4 Replies)
Discussion started by: banjo
4 Replies

2. Shell Programming and Scripting

howto run remotely call function from within script

Hi I have the following script : #!/bin/ksh #################### Function macAddressFinder ######################## macAddressFinder() { `ifconfig -a > ipInterfaces` `cat ipInterfaces` } ####################################################################### # # print... (2 Replies)
Discussion started by: presul
2 Replies

3. Shell Programming and Scripting

script to shorten usernames and output to file

Hopefully someone here can point me in the correct direction. I'm working on a username migration and am trying to map my users ols usernames to the new ones. Right now every user has a username of firstname.lastname i.e. john.doe I'm trying to create a bash or python script that will take... (3 Replies)
Discussion started by: binary-ninja
3 Replies

4. Shell Programming and Scripting

Need help optimizing this piece of code (Shell script Busybox)

I am looking for suggestions on how I could possibly optimized that piece of code where most of the time is spend on this script. In a nutshell this is a script that creates an xml file(s) based on certain criteria that will be used by a movie jukebox. Example of data: $SORTEDTMP= it is a... (16 Replies)
Discussion started by: snappy46
16 Replies

5. Shell Programming and Scripting

Script loops again and again and again and ...

Hi, Linux newbie here with what I'm guessing is silly questions. My script below is working in that it correctly copies files from the backup IP (10.0.91.1) back down to the Linux server but trouble is it loops continuously. It correctly downloads 100 files from the the IP 10.0.91.1... (1 Reply)
Discussion started by: MOWS
1 Replies

6. Shell Programming and Scripting

Bash Script to Ash (busybox) - Beginner

Hi All, I have a script that I wrote on a bash shell, I use it to sort files from a directory into various other directories. I have an variable set, which is an array of strings, I then check each file against the array and if it is in there the script sorts it into the correct folder. But... (5 Replies)
Discussion started by: sgtbobie
5 Replies

7. UNIX for Dummies Questions & Answers

How to shorten my code?

salary_range_report() { echo -e ${underline}$redYellow"\nSalary Range Report\n" tput sgr0 count_0_to_999=0 count_1000_to_2999=0 count_2000_to_5999=0 count_6000_to_9999=0 count_10000_above=0 for i in `cut -d "," -f4 $PAYROLL` #Loop Salary do if && then let... (4 Replies)
Discussion started by: eggisbad
4 Replies

8. UNIX for Dummies Questions & Answers

How can i use function for the below script to shorten it?

Hi All, i worte a shell script which will zcat the .gz file and write it in to a tmp file and then again cat the file and convert it to Dos mode. Next step is i am greping the file to search for the particular string on the 1st line and if the string does not exits it will insert the 1st line... (1 Reply)
Discussion started by: vikatakavi
1 Replies

9. Shell Programming and Scripting

Ps command and awk - shorten characters

ps -e -o pcpu -o pid -o user -o args | sort -k 1 | tail -6r %CPU PID USER COMMAND 0.3 223220 root /usr/tivoli/tsm/client/ba/bin/dsmc sched 0.2 411332 root /usr/sbin/syslogd 0.1 90962 root /usr/sbin/syncd 60 0.0 10572 root -ksh 0.0 94270 root -ksh ... (4 Replies)
Discussion started by: SkySmart
4 Replies

10. UNIX for Advanced & Expert Users

Howto stop loops in CentOS

Good morning, At the client location os is CentOS. In all the terminals i.e F1, F2, F3....F10 PING command is continuously running. I tried to terminate it using CTRL C or quit but unable to stop that command in all the terminals. How to stop that? Howto find batch files which are being... (3 Replies)
Discussion started by: sureshbabu.anis
3 Replies
nqs2pbs(1B)								PBS							       nqs2pbs(1B)

NAME
nqs2pbs - convert NQS job scripts to PBS SYNOPSIS
nqs2pbs nqs_script [pbs_script] DESCRIPTION
This utility converts a existing NQS job script to work with PBS and NQS. The existing script is copied and PBS directives, #PBS , are inserted prior to each NQS directive #QSUB or #@$ , in the original script. Certain NQS date specification and options are not supported by PBS. A warning message will be displayed indicating the problem and the line of the script on which it occurred. If any unrecognizable NQS directives are encountered, an error message is displayed. The new PBS script will be deleted if any errors occur. OPERANDS
nqs_script Specifies the file name of the NQS script to convert. This file is not changed. pbs_script If specified, it is the name of the new PBS script. If not specified, the new file name is nqs_script.new . NOTES
Converting NQS date specifications to the PBS form may result in a warning message and an incompleted converted date. PBS does not support date specifications of "today", "tomorrow", or the name of the days of the week such as "Monday". If any of these are encountered in a script, the PBS specification will contain only the time portion of the NQS specification, i.e. #PBS -a hhmm[.ss]. It is suggested that you specify the execution time on the qsub command line rather than in the script. Note that PBS will interpret a time specification without a date in the following way: - If the time specified has not yet been reached, the job will become eligible to run at that time today. - If the specified time has already passed when the job is submitted, the job will become eligible to run at that time tomorrow. PBS does not support time zone identifiers. All times are taken as local time. SEE ALSO
qsub(1B) Local nqs2pbs(1B)
All times are GMT -4. The time now is 04:57 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy