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

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.

Related

Shell alias expansion under ESXi host does not auto complete - AND - detecting if running interactively

Since ESXi does not come with bash, I am sourcing an .sh file to set up some custom aliases for common commands while connected via ssh.
On other distros like RHEL, I can type part of an alias and hit tab to autocomplete. This does not seem to work under ESXi 7.x.
Is there a switch or something that I can turn on to make autocomplete work for custom aliases, or is this just a limitation of the shell that ESX offers?
NOTE: If type l<tab> then I DO get the built in commands that start with L.
Also while I'm on the topic of the ESXi shell… On RHEL I have this line in my .bashrc file
[[ $- != *i* ]] && return
Purpose of this code being that if the current session is not being ran interactively then return else run rest of code.
When I run this on esx I get the error sh: *i*: unknown operand. Does the shell not support this substring methodology?
If I run echo $- then I get “smi” as the output.
Thanks
As you probably know ESXi provides ash (NOT bash) and Busybox. Although Busybox includes ash as I recall ESXi uses a custom built executable (check where /bin/ash points or doesn't point to). The Wikipedia article on ash gives a good overview of ash and its minimalist philosopy. Shell history was originally not included and autocompletion is definitely regarded as a nice to have that didn't make the cut. Sorry to be the bearer of bad news.

Can't get ebpf program jitted output using bpftool

When I run sudo bpftool prog show I get the following output
39: socket_filter name bpfprog1 tag e29cda32ba011d7f gpl
loaded_at 2019-09-08T14:21:57+0200 uid 1000
xlated 248B jited 169B memlock 4096B map_ids 30
but If I try to get the program jitted output with the following command
sudo bpftool prog dump jited tag e29cda32ba011d7f
I get an error message, as reported below:
Error: can't get prog info (3): Bad address
QUESTION: what am I doing wrong? XD
You most certainly use a bpftool version compiled from Linux 4.20 or older, and hit a bug that was fixed in version 5.0. Update bpftool, and dumping programs by tags should work again.
As a side note, I usually use program IDs or pinned path, as I find it more useful to retrieve the program I want. Depending on your use case, tags might make sense, especially if you often load the same programs without changes (so you would be sure to keep the same tags) and do not have them pinned.

redirecting echo with undefined variable

I'm running a script in solaris 11 with different results depending of the shell used.
The script has an echo redirecting to a file given by an environment value:
echo "STARTING EXEC" >> $FILE
ps. EXEC is just the message the script show, it's not using exec command.
If I execute the script without the variable FILE defined (using /usr/bin/ksh):
./start.sh[10]: : cannot open
and the script continue the execution.
The flags for ksh are:
echo $-
imsuBGEl
But if I change to /usr/xpg4/bin/sh, the script show me the echo in stdout and there is no error shown.
The flags for xpg4 sh are:
echo $-
imsu
I tried to change the flags with set +- (I can't remove El flags, but BG are removed ok), but can't get the same behavior.
Is there anything I can do to get the same result using ksh without cannot open error?
/usr/bin/ksh --version
version sh (AT&T Research) 93u 2011-02-08
I'll want the script keep going, showing the message in stdout, instead of showing the error just like it does now.
Like shellter said in the comments, the good thing to do is to check if the FILE variable is defined before doing anything. This is a script migration from an HPUX to a SOLARIS environment, and client think they must have the same result as before (we unset FILE variable before execution to test it).
You are likely running Solaris 11, not Solaris 64.
Should you want to have your scripts to work under Solaris 11 without having to search everywhere the bogus redirections, you can simply replace all shebangs (first line) by #!/usr/xpg4/bin/sh.
The final solution we are going to take is to install the ksh88 package and use it like default shell (/usr/sunos/bin/ksh). This shell have the same behavior the client had before, and we can let the scripts with no modifications.
The ksh used in solaris 11 is the 93 (http://docs.oracle.com/cd/E23824_01/html/E24456/userenv-1.html#shell-1)
Thanks #jlliagre and #shellter for your help.

SOLARIS 10 Date Arithmetic

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.

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.)