[KLUG Members] url encode in a bash script: solution for RH 9

Bruce Smith members@kalamazoolinux.org
Thu, 27 May 2004 11:40:23 -0400


--=-MF6IoGgHCrfri84U6hhA
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

> Tres bien, monsieur. 

Attached.  You can just run gcc on it:

  gcc -o modtime modtime.c

Or if you don't have the compiler installed, let me know and I can send
you a binary.

> As long as you tell me how to include C in a bash script.

"stat" and most other lines in your script are just compiled C programs.
Put the binary in your path, or supply the full path in the command.

You can check the return code for errors, or make sure the file exists
in the script before you call my program.

 - BS


--=-MF6IoGgHCrfri84U6hhA
Content-Disposition: attachment; filename=modtime.c
Content-Type: text/x-c; name=modtime.c; charset=UTF-8
Content-Transfer-Encoding: 7bit

#include <stdio.h>
#include <string.h>
#include <time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>

main(argc, argv)
int argc;
char *argv[];
{
struct stat fileinfo;
struct tm *t;
	if (argc != 2) exit(1);
	if (stat((argv[1]), &fileinfo) != 0) exit(2);
	t=localtime(&fileinfo.st_mtime);
	t->tm_mon++;
	t->tm_yday++;

	/* date */
	printf("%.4u-%.2u-%.2u\n", t->tm_year+1900, t->tm_mon, t->tm_mday);

	/* time */
	/* printf("%.2u:%.2u:%.2u\n",  t->tm_hour, t->tm_min, t->tm_sec); */

	/* day of week  0=Sun, 1=Mon, ... 6=Sat   */
	/* printf("%d\n", t->tm_wday); */
}

--=-MF6IoGgHCrfri84U6hhA--