Sponsored Content
Full Discussion: POSIX compliance...
Operating Systems OS X (Apple) POSIX compliance... Post 302977055 by wisecracker on Monday 11th of July 2016 05:32:40 PM
Old 07-11-2016
Hi Don...
You are of course correct in what you have quoted. I was well aware of my sleep alternative's limitations so I decided to embed a delay into a shell script. You suggested a C program to do the job, so here goes...
Code:
#!/bin/sh
# delay <milliseconds>
# MacBook Pro, 13 Inch, Circa August 2012, OSX 10.7.5, using sh and limited /bin/echo command.
clear

# Use /bin/echo here for minimalist echo command.
/bin/echo '/* delay.c */
/* Usage:- delay <milliseconds[0 to 1000000]> */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

int main(int argc, char *argv[])
{
	unsigned int milliseconds;
	milliseconds = 0;

	/* This allows for NULL millisecond argument and more arguments too. */
	if (argc <= 1 || argc >= 3)
	{
		printf ("\nUsage:- delay <milliseconds[0 to 1000000]>\n\n");
		return 1;
	}

	/* Check for number of characters, no less than 1 and no more than 7. */
	if (strlen(argv[1]) <= 0 || strlen(argv[1]) >= 8) (argv[1]) = "0";

	/* Characters in function atoi() returns integer 0. */
	milliseconds = atoi(argv[1]);

	/* Finally, ONLY allow 0 to 1000000 range. */
	if (milliseconds <= 0 || milliseconds >= 1000001) milliseconds = 0;

	usleep (milliseconds * 1000);
	return 0;
}' > /tmp/delay.c
echo "Show C source..."
cat /tmp/delay.c
echo "Compile the C source..."
gcc /tmp/delay.c -o /tmp/delay
ls -l /tmp/delay*
echo "Delay for 3 seconds - /tmp/delay 3000..."
/tmp/delay 3000
echo "Return code is $?..."
echo "Now show error report - /tmp/delay..."
/tmp/delay
echo "Return code is $?..."

Results:-
Code:
Last login: Mon Jul 11 22:09:24 on ttys000
AMIGA:barrywalker~> cd Desktop/Code/Shell
AMIGA:barrywalker~/Desktop/Code/Shell> ./mS_delay.sh


Show C source...
/* delay.c */
/* Usage:- delay <milliseconds[0 to 1000000]> */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

int main(int argc, char *argv[])
{
	unsigned int milliseconds;
	milliseconds = 0;

	/* This allows for NULL millisecond argument and more arguments too. */
	if (argc <= 1 || argc >= 3)
	{
		printf ("\nUsage:- delay <milliseconds[0 to 1000000]>\n\n");
		return 1;
	}

	/* Check for number of characters, no less than 1 and no more than 7. */
	if (strlen(argv[1]) <= 0 || strlen(argv[1]) >= 8) (argv[1]) = "0";

	/* Characters in function atoi() returns integer 0. */
	milliseconds = atoi(argv[1]);

	/* Finally, ONLY allow 0 to 1000000 range. */
	if (milliseconds <= 0 || milliseconds >= 1000001) milliseconds = 0;

	usleep (milliseconds * 1000);
	return 0;
}
Compile the C source...
-rwxr-xr-x  1 barrywalker  wheel  8824 11 Jul 22:14 /tmp/delay
-rw-r--r--  1 barrywalker  wheel   802 11 Jul 22:14 /tmp/delay.c
Delay for 3 seconds - /tmp/delay 3000...
Return code is 0...
Now show error report - /tmp/delay...

Usage:- delay <milliseconds[0 to 1000000]>

Return code is 1...
AMIGA:barrywalker~/Desktop/Code/Shell> _

ShellCheck results for the script:-
Code:
$ shellcheck myscript
 
Line 7:
/bin/echo '/* delay.c */
          ^-- SC2028: echo won't expand escape sequences. Consider printf.

$ _

I don't want to expand any escape sequences...

Hi drl...
I could do it in python too.
Code:
#!/usr/bin/python
# fpt.py <floating point time>
import time
import sys
fpt=float(sys.argv[1])
time.sleep(fpt)
exit(0)

Thanks both for the feedback...

Last edited by wisecracker; 07-12-2016 at 06:24 AM.. Reason: Correct typo.
 

5 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

sudo & Sox compliance

Hello, I am trying to convince my boss to stop allowing our users to login as root (superuser). Currently our users login to our unix server with their own account, then as needed, they will do an su and put in the root password. This scares me, for a bunch of reasons. Mainly, one is that we... (1 Reply)
Discussion started by: rwallaceisg
1 Replies

2. UNIX for Dummies Questions & Answers

man synopsis standard compliance

In different online sources, I found bits and pieces of information about those square and angular brackets and pipes. From what I have read, I can conclude it looks like this: 1. Options outside any brackets are mandatory 2. Options inside these < .. > are mandatory too 3. Options inside ... (4 Replies)
Discussion started by: vkleban
4 Replies

3. Cybersecurity

PCI DSS Compliance : Insecure Communication Has Been Detected

From the nessus scanner tool report i got below vulnerability PCI DSS Compliance : Insecure Communication Has Been Detected http://www.tenable.com/plugins/index.php?view=single&id=56208 As per the description given in above link - I am not able to understand How to find insecure port... (2 Replies)
Discussion started by: saurabh84g
2 Replies

4. Red Hat

Looking for PCI Compliance tool for Redhat Lix.

Hi i am in new to Linux world . I have been assigned to a project to find out a tool that will fulfill the PCI compliance for Linux servers for Audit process. anyone have any recommendation on that. Do Rad hat have any native application or plug-ins which we can use for that. (1 Reply)
Discussion started by: sahasuman
1 Replies

5. HP-UX

Password compliance setting

I need to set password compliance for some servers in my company. However, the requirements are that we need to set different password policies for 3 different user groups within the company. These are : System Users: i.e root, etc Batch/Application Users: oracle, bscs, etc Standard User:... (0 Replies)
Discussion started by: anaigini45
0 Replies
All times are GMT -4. The time now is 06:22 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy