Passing Day in string


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Passing Day in string
# 8  
Old 02-07-2019
Quote:
Originally Posted by danielshell
Thank you, RudiC!

Code:
root:root> uname -a
HP-UX B.11.31 U ia64 0123365846 unlimited-user license

It is HP-UX, so it is kind of tough.. I am getting this error

Code:
root:> date +"%b %_d" -d "2 day ago"
 date: bad format character - _


Welcome.



The first thing I would try encountering that error message is relaunch the command without the _ and / or consult the man page. Having said that, I'm afraid that your date will fail on the -d option. So - rely on e.g. rdrtx1's proposal. Or - search these fora for "HP-UX" and "date" keywords.
This User Gave Thanks to RudiC For This Post:
# 9  
Old 02-07-2019
Thank you so much!!! I will modify my script and run it for 3 days to validate that everything runs ok.
Appreciate it your help! I will keep you posted!
# 10  
Old 02-08-2019
I am new to shell programming, here is what I did.

Code:
#!/bin/sh

# Code is POSIX compliant


currentDate="$(date -R)"


counter=0

for word in $currentDate
do

  # We ignore the day of the week.
  if [ $counter -eq 0 ]
  then

    counter=$((counter+1))
    continue
  fi


  # We store the day of the month.
  if [ $counter -eq 1 ]
  then
    dayOfMonth=$word

    counter=$((counter+1))

    continue
  fi


# We store the name of the month.
  if [ $counter -eq 2 ]
  then
    month=$word

    break
  fi

done


echo "$month $dayOfMonth"


exit 0


It outputs:
Code:
Feb 08

From there, it remains to create the days you want, from this result.
This User Gave Thanks to johnprogrammer For This Post:
# 11  
Old 02-08-2019
I completed the code:
Code:
#!/bin/sh

# Code is POSIX compliant

tput clear

currentDate="$(date -R)"


counter=0

for word in $currentDate
do

  # We ignore the day of the week.
  if [ $counter -eq 0 ]
  then

    counter=$((counter+1))
    continue
  fi


  # We store the day of the month.
  if [ $counter -eq 1 ]
  then
    dayOfMonth=$word

    counter=$((counter+1))

    continue
  fi

  # We store the name of the month.
  if [ $counter -eq 2 ]
  then
    month=$word

    break
  fi

done


dayOfMonth=$(echo "$dayOfMonth" | tr --delete 0)


day1="$month $((dayOfMonth-5))"

day2="$month $((dayOfMonth-4))"

day3="$month $((dayOfMonth-3))"


echo "day 1: $day1"
echo "day 2: $day2"
echo "day 3: $day3"


exit 0

It outputs:
Code:
day 1: Feb 3
day 2: Feb 4
day 3: Feb 5
[john@manjaromatepc Downloads]$

This User Gave Thanks to johnprogrammer For This Post:
# 12  
Old 02-18-2019
I thought of a better way on this script (if it is possible)

Code:
lpstat -o |grep -v bytes |sort -nkb1

returns the outputs, i.e.

Code:
sld-8638            prod         priority 1  Feb 14 11:51
sld-8719            prod         priority 1  Feb  8 09:24
sld-8782            prod         priority 1  Feb 14 12:13
sld-8788            prod         priority 1  Feb 14 12:14
sld-8790            prod         priority 1  Feb 14 12:14
sld-8800            prod         priority 1  Feb 14 12:18
sld-8961            prod         priority 1  Feb 16 14:53
... <snipped> ....

If we can add
Code:
mtime +3

like:

Code:
lpstat -o |grep -v bytes |sort -nkb1 | ?? mtime +3 ?? |awk {'print $1'} > cleanuplist.txt

, the script can be a whole lot simpler and better.

But, HP-UX doesn't have mtime..

Code:
root:> man mtime
No manual entry for mtime.

Is there a way that we can add the equivalent of "mtime +3" to
Code:
lpstat -o |grep -v bytes |sort -nkb1 | ?? mtime +3 ?? |awk {'print $1'} > cleanuplist.txt

?

Thank you so much!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Passing string from bash to sqlplus

Hello, I have file (PARFILE) with string on first line: INCLUDE=SCHEMA:"IN\( 'SCHEMA1','SCHEMA2','SCHEMA3' \)"In .sh script I use: .... IMPORT_SCHEMA=`awk 'NR==1{print $2}' ${PARFILE}` ...print $2 is because 'SCHEMA1','SCHEMA2','SCHEMA3' is 2nd column in file echo "$IMPORT_SCHEMA"... (5 Replies)
Discussion started by: DjukaZg
5 Replies

2. Homework & Coursework Questions

passing letters from an array into a string for string comparison

attempting the hangman program. This was an optional assignment from the professor. I have completed the logical coding, debugging now. ##I have an array $wordString that initializes to a string of dashes ##reflecting the number of letters in $theWord ##every time the user enters a (valid)... (5 Replies)
Discussion started by: lotsofideas
5 Replies

3. Shell Programming and Scripting

Reading a string and passing passing arguments to a while loop

I have an for loop that reads the following file cat param.cfg val1:env1:opt1 val2:env2:opt2 val3:env3:opt3 val4:env4:opt4 . . The for loop extracts the each line of the file so that at any one point, the value of i is val1:env1:opt1 etc... I would like to extract each... (19 Replies)
Discussion started by: goddevil
19 Replies

4. Shell Programming and Scripting

Passing varibles as a string argument ?

For example test.sh: test="teststring" cmd=$1 $cmd For some reason I'm NOT seeing "teststring" when I type: ./test.sh "echo $test" Any ideas on how to get around this? I've tried commands like: ./test.sh "echo $($test)" ./test.sh "echo '$test'" And many variations to no... (6 Replies)
Discussion started by: secops
6 Replies

5. UNIX for Dummies Questions & Answers

Day of the week from a string

Hi All, I need to know how to derive the day of the week by passing the value in following format: Feb 28 2010 The output I'm expecting is Sunday or Sun. I know, I can use the following code to get the day of the week. date +%a But I want to pass the value as a string. Please help... (11 Replies)
Discussion started by: shash
11 Replies

6. Shell Programming and Scripting

passing string which includes metacharacters

I'm trying to create a bash script that takes a URL as one of its arguments like this: ./script.sh http://url.cfm?asdf&asdf=234 variable=$1 echo $variable I'm having trouble storing the URL because it contains the meta character "&" which is being interpreted... thus when I run the... (4 Replies)
Discussion started by: kds1398
4 Replies

7. Shell Programming and Scripting

Help needed passing string to command

hi to all code: </div> command... "command_name arg1 arg2 option=xxxxx" example --- useradd username group=xxxxxx. </div> when someone ran this command it point to some other script (say script1), mean post execution of command. in the script1 i need only "xxxxx" value. then i... (5 Replies)
Discussion started by: honeym210
5 Replies

8. Shell Programming and Scripting

Passing string variables

HI all, Very new to shell programming and just wanted some help on how to solve the following problem. I have a small shell script which searches a given file and extracts some string parameters. I want to now be able to call this script from another shell script and somehow pass the parameters... (11 Replies)
Discussion started by: pxy2d1
11 Replies

9. Shell Programming and Scripting

Passing string from function with '*'

Hi I have a shell function which returns string(ksh). The string is an sql statement. This statement can have '*' in its content (i.e. select 100 / 2 *100 from dual). When this happens ret_str will have contents of current directry I run the script from build in sql. Is there any way to fix it... (2 Replies)
Discussion started by: zam
2 Replies

10. Shell Programming and Scripting

Passing a string parameter to a function

I need to pass a parameter to a function in a script. My parameter is a string. When I display the parameter within my function, I only get the first word from string I pass in. How can I make the function receive the whole string (and not terminate at the first space it encounters)?. part of... (1 Reply)
Discussion started by: fastgoon
1 Replies
Login or Register to Ask a Question