Commit ac9c15bf by PotatoGim

.gitignore 추가

parent 8d478c48
*~
*.o
*.exe
#!/bin/bash
#################################################
# Script Name : createdel.sh #
# Purpose : Create a file for testing #
# Author : Potato Kim #
# Date : Wed Jan 4 16:47:00 KST 2012 #
#################################################
OPTERR=65
home=
fileNum=100
fileSize=1024
time=5
dirName=aging_test
fileName=file
if [ $# -eq "0" ]; then
echo "$0 [-n num-files] [-s file size] [-t time to sleep] target_directory"
exit $OPTERR
fi
while getopts ":n:s:t:h" Option
do
case $Option in
n) fileNum=$OPTARG;;
s) fileSize=$OPTARG;;
t) time=$OPTARG;;
h) echo "$0 [-n num-files] [-s file size] [-t time to sleep] target_directory"
exit 0;;
esac
done
shift $(($OPTIND - 1))
home=$1
if [ ! -d "$home" ]; then
echo "Specified wrong the target directory."
exit $OPTERR
fi
#################################################
# Function Name : create #
# Purpose : Creating a file #
# Author : Potato Kim #
# Date : Tue Jan 3 14:42:08 KST 2012 #
#################################################
create ()
{
local i=0
until [ "$i" -eq "$fileNum" ]; do
dd if=/dev/zero of=$fileName\_$((i+1)) bs=$fileSize count=1 1>/dev/null 2>&1
let "i += 1"
done
sleep $time
until [ "$i" -eq "0" ]; do
rm -f $fileName\_$((i+1)) 1>/dev/null 2>&1
let "i -= 1"
done
return $i
}
#################################################
echo "started at `date`"
mkdir -p $home/aging_test && cd $home/aging_test
while [ 1 ]; do
create
sleep $time
done
cd ..
rmdir $home/aging_test
echo "ended at `date`"
#!/bin/bash
# $1 = root
# $2 = list-file
cnt=0
while read -r target
do
echo "setfacl -m u:${target#*:} $1${target/:*}"
setfacl -m "u:${target#*:}" "$1${target/:*}"
echo "setfacl -m g:${target#*:} $1${target/:*}"
setfacl -m "g:${target#*:}" "$1${target/:*}"
echo [ $cnt ]
cnt=$[ $cnt + 1 ]
done < $2
#!/bin/bash
# Name @ moni_renamer.sh
# Purpose @ For renaming a moniwiki pages
# Author @ Ji-Hyeon, Gim (potatogim@gluesys.com)
# Organization @ Co., Ltd. Gluesys.
# Date @ 2012. 02. 02. (목) 14:49:54 KST
find ./data -name "*Develop_2fOffiStor_5fProjec_2f*" | sed -e 'p' -e 's/Develop_2fOffiStor_5fProjec_2f/Develop_2fProject_2fOffiStor_2f/g' | xargs -n2 mv
find ./pds -name "*Develop_2fOffiStor_5fProjec_2f*" | sed -e 'p' -e 's/Develop_2fOffiStor_5fProjec_2f/Develop_2fProject_2fOffiStor_2f/g' | xargs -n2 mv
find ./data -exec perl -pi -e "s/\/OffiStor_Projec/Project\/OffiStor/g" {} \;
@REM Author : PotatoGim (potatogim@gluesys.com)
@REM Created : 1:28 2013-07-17
@ECHO OFF
SETLOCAL EnableDelayedExpansion
SET "domain=asia.potato-ad.com"
SET "groupdn=ou=ASIA-Users,dc=asia,dc=potato-ad,dc=com"
FOR /L %%i IN (1 1 10000) DO (
SET "num=0000%%i"
SET "num=!num:~-5!"
DSADD USER "cn=user!num!,!groupdn!" -samid "user!num!" -upn "user!num!@!domain!" -display "user!num!" -pwd "gluesys^^!^^!" -pwdneverexpires yes 1>NUL
ECHO user!num! have added to !groupdn!
@REM TIMEOUT /t 3
)
PAUSE
\ No newline at end of file
/*!
* charupcount
*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
int main (void) {
int i, count, posNum, tempLen;
char *test = NULL;
char temp[10] = {0,};
printf ("Input prefix : "); scanf ("%s", temp);
if (strlen(temp) > 10) {
fprintf (stderr, "Prefix length is limited as 10\n");
return;
}
printf ("Input number : "); scanf ("%d", &count);
posNum = (int) log10f ((float)count) + 1;
test = (char *) calloc (strlen(temp) + posNum, sizeof(char));
test = strncpy (test, temp, strlen(temp));
tempLen = strlen(test);
for (i = tempLen; i < tempLen + posNum; i++) {
test[i] = 48;
}
for (i = 0; i <= count; i++) {
upcount (test, i, (int) log10f ((float) i) + 1);
printf ("Number : %s\n", test);
}
return 0;
}
void upcount (char *test, int count, int posNum) {
int i;
for (i=1; i<=posNum; i++) {
test [strlen(test)-i] = (count%10) + 48;
count /= 10;
}
}
/*!
* fifo_c.c
*
* Author : Gim Ji-Hyeon (potatokim@gluesys.com)
* Version :
* Created : 2012. 09. 05. (수) 13:54:44 KST
*
* Description about this file
*
* (c) Gluesys Co.,Ltd.
*****************************************************************************
* Etc.
*
*/
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int main (void)
{
FILE *fp;
FILE *fp1, *fp2;
char buf[2048]={0,};
fp = fopen("./fifo", "r");
unlink ("./fifo1");
unlink ("./fifo2");
mkfifo ("./fifo1", 0666);
mkfifo ("./fifo2", 0666);
fp1 = fopen("./fifo1", "w");
fp2 = fopen("./fifo2", "w");
while (1)
{
fgets(buf, sizeof(buf), fp);
printf ("READ : %s", buf);
fprintf (fp1, "%s\n", buf);
fprintf (fp2, "%s\n", buf);
fflush (fp);
fflush (fp1);
fflush (fp2);
}
fclose (fp);
fclose (fp1);
fclose (fp2);
return 0;
}
/*!
* fifo_c.c
*
* Author : Gim Ji-Hyeon (potatokim@gluesys.com)
* Version :
* Created : 2012. 09. 05. (수) 13:54:44 KST
*
* Description about this file
*
* (c) Gluesys Co.,Ltd.
*****************************************************************************
* Etc.
*
*/
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int main (void)
{
FILE *fp1;
char buf[2048]={0,};
fp1 = fopen("./fifo1", "r");
while (1)
{
fgets(buf, sizeof(buf), fp1);
printf ("READ : %s", buf);
fflush (fp1);
}
fclose (fp1);
return 0;
}
/*!
* fifo_c.c
*
* Author : Gim Ji-Hyeon (potatokim@gluesys.com)
* Version :
* Created : 2012. 09. 05. (수) 13:54:44 KST
*
* Description about this file
*
* (c) Gluesys Co.,Ltd.
*****************************************************************************
* Etc.
*
*/
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int main (void)
{
FILE *fp2;
char buf[2048]={0,};
fp2 = fopen("./fifo2", "r");
while (1)
{
fgets(buf, sizeof(buf), fp2);
printf ("READ : %s", buf);
fflush (fp2);
}
fclose (fp2);
return 0;
}
/*!
* fifo_s.c
*
* Author : Gim Ji-Hyeon (potatokim@gluesys.com)
* Version :
* Created : 2012. 09. 05. (수) 13:51:20 KST
*
* Description about this file
*
* (c) Gluesys Co.,Ltd.
*****************************************************************************
* Etc.
*
*/
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
int main (void)
{
FILE *fp;
char buf[2048] = {0,};
unlink("./fifo");
mkfifo("./fifo", 0666);
fp = fopen("./fifo", "w");
printf ("INPUT : ");
while (1)
{
scanf ("%s", buf);
fprintf (fp, "%s\n", buf);
fprintf (stdout, "BUF : %s\nINPUT : ", buf);
fflush (fp);
}
fclose (fp);
return 0;
}
/*!
* file_lock_1.c
*
* Author : Gim Ji-Hyeon (potatokim@gluesys.com)
* Version :
* Created : 2012. 08. 07. (화) 09:46:13 KST
*
* Description about this file
*
* (c) Gluesys Co.,Ltd.
*****************************************************************************
* Etc.
*
*/
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <errno.h>
#define err_abort(code,text) do { \
fprintf (stderr, "%s at \"%s\":%d: %s\n", \
text, __FILE__, __LINE__, strerror(code)); \
abort(); \
} while(0);
#define errno_abort(text) do { \
fprintf (stderr, "%s at \"%s\":%d: %s\n", \
text, __FILE__, __LINE__, strerror(errno)); \
abort(); \
} while(0);
#define LOCK_FILE "./lock_test"
int ptt_lock (int fd, int flag);
int
main (int argc, const char *argv[])
{
int fd = open(LOCK_FILE, O_CREAT|O_RDWR, 0644);
if (ptt_lock(fd, 1) < 0) {
errno_abort ("WRLOCK FAILURE");
goto FAULT;
}
else {
printf ("Locked : %d\n", getpid());
sleep (10);
if (ptt_lock(fd, 0) < 0) {
errno_abort ("UNLOCK FAILURE");
goto FAULT;
}
}
return 0;
FAULT:
return -1;
}
int
ptt_lock (int fd, int flag)
{
struct flock fl = {
.l_type = 0,
.l_start = 0,
.l_whence = SEEK_SET,
.l_len = 0
};
switch (flag) {
case 0:
fl.l_type = F_UNLCK;
break;
case 1:
fl.l_type = F_WRLCK;
break;
case 2:
fl.l_type = F_RDLCK;
break;
}
if (fcntl(fd, F_SETLK, &fl) < 0)
goto FAULT;
return 0;
FAULT:
return -1;
}
/*
* =========================================================================
*
* Filename: pipe_exam1.c
*
* Description:
*
* Version: 1.0
* Created: 2012. 03. 29. 20:29:05
* Compiler: gcc
*
* Author: Gim Ji-Hyeon (http://www.potatogim.net)
* E-Mail: jhk7799@daum.net
*
* =========================================================================
*/
#include <stdio.h>
#include <fcntl.h>
#include <sys/types.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#define REQUEST "Did you get my message?"
#define RESPONSE "Yes, of course."
int main (int argc, char *argv[])
{
int ctop[2], ptoc[2];
pid_t pid;
char buf[30] = {0,};
if ((pipe(ctop)>0) || (pipe(ptoc)>0)) {
perror ("pipe()");
return -1;
}
if (fork() == 0) {
/* Child */
close (ptoc[1]);
close (ctop[0]);
dup2 (ptoc[0], 0);
dup2 (ctop[1], 1);
read (ptoc[0], buf, sizeof(buf));
memset (buf, 0, sizeof(buf));
strncpy (buf, RESPONSE, strlen(RESPONSE));
write (ctop[1], buf, sizeof(buf));
exit (EXIT_SUCCESS);
}
else {
/* Parent */
close (ptoc[0]);
close (ctop[1]);
strncpy (buf, REQUEST, strlen(REQUEST));
printf ("Parent : %s\n", buf);
write (ptoc[1], buf, sizeof(buf));
read (ctop[0], buf, sizeof(buf));
printf ("from Child : %s\n", buf);
wait ((int *) 0);
}
return 0;
}
/*!
* printf_center.c
*/
#include <stdio.h>
#include <math.h>
#include <string.h>
int main (void)
{
int a, b, x;
x = 10000;
a = strlen("HELLO")/2;
b = (int) log10f ((x==0)?1:x) + 1;
b /= 2;
printf ("|| %*s%*s ||\n", 10 + a, "HELLO", 10 - a, "");
printf ("|| %*d%*s ||\n", 10 + b, x, 10 - b, "");
return 0;
}
/*
* =========================================================================
*
* Filename: recur_rm.c
*
* Description:
*
* Version: 1.0
* Created: 2013년 09월 16일 15시 08분 06초
* Compiler: gcc
*
* Author: Gim Ji-Hyeon (http://www.potatogim.net)
* E-Mail: jhk7799@daum.net
*
* =========================================================================
*/
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <dirent.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
int
recur_rm (const char *path)
{
struct dirent **namelist;
int ndir;
struct stat st;
char buf [4096];
ndir = scandir (path, &namelist, 0, alphasort);
while (ndir--)
{
if (strcmp(namelist[ndir]->d_name, ".") == 0
|| strcmp(namelist[ndir]->d_name, "..") == 0) {
continue;
}
snprintf (buf, sizeof(buf), "%s/%s", path, namelist[ndir]->d_name);
if (stat(buf, &st) < 0) {
perror ("Failed to get file stat : ");
goto FAULT;
}
if (S_ISDIR(st.st_mode)) {
recur_rm (buf);
if (rmdir(buf) < 0) {
perror ("Failed to delete file : ");
goto FAULT;
}
}
else {
if (unlink(buf) < 0) {
perror ("Failed to delete file : ");
goto FAULT;
}
}
}
rmdir (path);
if (namelist != NULL) {
free (namelist);
namelist = NULL;
}
return 0;
FAULT:
if (namelist != NULL) {
free (namelist);
namelist = NULL;
}
return -1;
}
int
main (int argc, const char *argv[])
{
if (recur_rm(argv[1]) < 0) {
printf ("Error!\n");
return -1;
}
return 0;
}
/*!
* rot_log.c
*
* Created : 2012. 07. 02. (월) 14:32:54 KST
*
* Example for rotating log file...
*/
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
#define LOG_PATH "/var/log/"
#define LOG_FILE "rot_log.log"
#define LOG_MAX_FSIZE 2048
int
main (int argc, char *argv[])
{
int pathlen, filelen, i;
char *logName, *newName, *rotName;
struct stat st;
pathlen = strlen(LOG_PATH);
filelen = strlen(LOG_FILE);
memset (logName, 0, sizeof(logName));
memcpy (logName, LOG_PATH, pathlen);
memcpy (logName+pathlen, LOG_FILE, filelen);
newName = (char*)calloc(pathlen+filelen+10, sizeof(char));
rotName = (char*)calloc(pathlen+filelen+10, sizeof(char));
if (access(logName, F_OK) == 0) {
if (stat(logName, &st) == -1)
return;
if (st.st_size > LOG_MAX_FSIZE) {
memcpy (newName, logName, pathlen+filelen);
memcpy (rotName, logName, pathlen+filelen);
for (i=1; ; i++)
{
sprintf (newName, "%s.%d", logName, i);
if (access(newName, F_OK) == -1)
break;
}
for (i+=1; i>1; i--)
{
sprintf (rotName, "%s.%d", logName, i-1);
sprintf (newName, "%s.%d", logName, i);
rename (rotName, newName);
}
sprintf (newName, "%s.%d", logName, i);
rename (logName, newName);
}
}
return 0;
}
/*
* =========================================================================
*
* Filename: rwepopen_example.c
*
* Description:
*
* Version: 1.0
* Created: 2013년 09월 16일 15시 09분 07초
* Compiler: gcc
*
* Author: Gim Ji-Hyeon (http://www.potatogim.net)
* E-Mail: potatogim@gluesys.com
* Organization: Gluesys Co. Ltd.
*
* =========================================================================
*/
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
pid_t rwepopen (const char *exe, const char * const argv[], int *rwepipe);
int
main (int argc, const char * const argv[])