SOLARIS 10 Date Arithmetic - date

I am using X86 SOLARIS 10 and need the following bash script to get yesterday's date.
#!/usr/local/bin/bash
#ds=`date '+%Y%m%d' -d "+2 days"`
ds=`GMT+24 date +%Y%m%d`
#ds=`date --date yesterday +%Y%m%d`
echo $ds
Getting an error "GMT+24: command not found". Also, tried the methods that are commented without success. Any suggestion

You can't do much date arithmetic with Solaris's own date command. As others have pointed out you'll need GNU date.
See this link, which includes information on getting GNU date (part of GNU coreutils package) on Solaris. Make it a rule to always deploy the minimal GNU tools on your Solaris servers (see link). Make it part of your company's default install. Then you won't get into these issues. Or move to more recent Solaris(*) where GNU date is installed by default.
*) Solaris 10 is getting fairly old now that we're in Dec 2014.

Related

Linux-wget command for certain time

I am using wget command for download in terminal
Is there an option in the wget command that the download starts at a certain date and time?
Thanks
Is there an option in the wget command that the download starts at a certain date and time?
So far I know no, you might use at to launch any command at predefined time. Simple example usage: download https://www.example.com at 12:00
echo "wget https://www.example.com" | at 12:00
Note that you need to activate atd (daemon, see linked article) before using at. If you want to know more about possible ways of specifying time read man page of at.

How to subtract or add days or months to a date on Solaris?

Linux date has the -d feature which is missing in Solaris. So how can I go about subtracting or adding days or months to a date on Solaris.
you still can do this with perl or python oneliners, e.g., substract one day from current date:
$ date
Thu May 14 15:31:49 MEST 2015
$ python -c "from datetime import datetime, timedelta; print (datetime.now() - timedelta(1)).strftime('%c');"
Wed May 13 15:31:58 2015
What you need is GNU date for Solaris. (Linux uses GNU tools)
If you are using a recent version of Solaris (no my friend, Solaris 10 can no longer be considered a recent version of Solaris) then it is installed by default. Just use gdate command instead of date command.
This reply has more answers for you. Just follow the links in that reply for what to do on Solaris 10. You sysadmin may already have done this for you. Before you proceed: Have you checked if gdate is available on your system ?

How to increase one hours current date in DEC UNIX 4.0?

I need to add one hours to current date in DEC UNIX V4.0?
I tried "date" command but in this version of that command "-v" or "-s" and etc switch doesn't work.
for example:
date -s "5 seconds"
doesn't work.
I assume you have already read the DEC manual page and observed that there is no option that matches the -v or -s options in GNU date. From that, you will conclude that you'll have to write your own code or get someone else's already written code to do the job — and you'll conclude that installing someone else's working code is easier than writing your own code.
The simplest fix, therefore, is to install GNU coreutils and use the date command from that. Of course, there are some tricky bits to deal with. You'll probably not want to install the GNU date command in /bin or /usr/bin because that might break other scripts that expect the DEC version of the date command (it probably won't, but it might, and you're likely to be cautious — if you weren't cautious, you wouldn't still be using DEC UNIX). So, you probably need to add it to /usr/local/bin, or maybe you create a new directory such as /usr/gnu/bin (add --prefix=/usr/gnu to the ./configure command when you build the core utilities). And then you ensure that the commands that need to use GNU date reference it explicitly. (Commands that don't insist on using GNU date should continue to use DEC date.)

Why is the backticks operator in Perl not working without the quotes on Windows?

I'm pretty new to Perl, so forgive me if the question is trivial.
At work I have got an assignment to create a script which would send out e-mails when other developers would miss the due date of their tasks. As whole thing would have to work on Windows, using Strawberry Perl, I have used windows command date /T to perform the date check. I have called external commands quite a lot, using the backticks operator, but in this particular case the backticks would not work:
my $date = `date /T`;
Outputs:
date: invalid date `/T'
Fixed using some additional quotes:
my $date = `"date /T"`
Outputs:
Mon 07/07/2014
My question is: why is that?
I would get that if the other external calls with backticks would work the same, but that's the only one I have to call that way, to make it work.
You seem to be accidentally using the Cygwin/GnuTools version of date.
Under a Windows command prompt, date /T gives the current time.
This is not an executable, this is a command.
However, running date /T under the Cygwin/GnuTools environment gives date: invalid date '/T'.
This is because the environment 1) cannot see the Windows date command and 2) finds a date executable in their PATH environment variable and runs it instead.

porting from solaris to linux(i.e sun command)

now i am working in porting (i.e solaris to linux)project..i am using one command i.e sun command in solaris ,but i am not able to find equivalent command in linux .if knows anyone please tell me
following is the man page for sun commamd in solaris(i.e man sun)
User Commands machid(1)
NAME
machid, sun, iAPX286, i286, i386, i486, i860, pdp11, sparc,
u3b, u3b2, u3b5, u3b15, vax, u370 - get processor type truth
value
SYNOPSIS
sun
iAPX286
i386
pdp11
sparc
u3b5
u3b15
vax
u370
DESCRIPTION
The following commands will return a true value (exit code
of 0) if you are using an instruction set that the command
name indicates.
sun True if you are on a Sun system.
iAPX286 True if you are on a computer using an
iAPX286 processor.
i386 True if you are on a computer using an
u370 True if you are on an IBMO System/370 com-
puter.
The commands that do not apply will return a false (non-
zero) value. These commands are often used within makefiles
(see make(1S)) and shell scripts (see sh(1)) to increase
portability.
ATTRIBUTES
See attributes(5) for descriptions of the following attri-
butes:
____________________________________________________________
| ATTRIBUTE TYPE | ATTRIBUTE VALUE |
|_____________________________|_____________________________|
| Availability | SUNWcsu |
|_____________________________|_____________________________|
SEE ALSO
make(1S), sh(1), test(1), true(1), uname(1), attributes(5)
NOTES
SunOS 5.10 Last change: 5 Jul 1990 2
User Commands machid(1)
The machid family of commands is obsolete. Use uname -p and
uname -m instead.
regards,
ven
Based on what you've added, I'd say that you can replace sun with false, and check the output of uname -p or uname -m instead.
I can find no mention of the sun command in the Solaris documents (either the user or system administration ones). If you mean the sum command, that should be available, or you probably want to look at cksum.
It's possible your command may be a local one in which case you'll need to tell us what it's supposed to do so we can tell you the alternatives. In terms of figuring it out, you should post:
the first bit of output from man sun.
the output of which sun.
the first 20-odd lines from that file (assuming it's a script rather than binary file).
Following your question update, it looks like you have some code that depends on the sun command return value. That will return true on a Sun and false everywhere else.
So the easiest solution is to probably just create a sun script that returns false:
#!/bin/bash
#
# sun command on non-Sun systems
exit 1
However, it's probably not going to be that simple. Obviously there are some platform-specific things going on there that you will have to add code in for Linux. That doesn't directly affect the sun command but all the stuff that happens when sun returns 0 will have to be done for Linux as well.
If you do a uname -o on Linux, you should get back "Linux" somewhere in the string (from memory). That should be enough to identify the operating system which is probably all you need.
The detection of machine and/or processor is probably not that relevant for software unless you're shipping binary executables for all platforms and selecting which ones to run dynamically.