Posts

Showing posts with the label linux

What is this $PATH in Linux and how to modify it

Image
Clash Royale CLAN TAG #URR8PPP What is this $PATH in Linux and how to modify it I have a few questions on this $PATH in Linux. I know it tells the shell which directories to search for executable files, so: 3 Answers 3 To get your path current $PATH variable type in: $PATH echo $PATH It tells your shell where to look for binaries. Yes, you can change it - for example add to the $PATH folder with your custom scripts. $PATH So: if your scripts are in /usr/local/myscripts to execute them you will have to type in a full path to the script: /usr/local/myscripts/myscript.sh After changing your $PATH variable you can just type in myscript.sh to execute script. /usr/local/myscripts /usr/local/myscripts/myscript.sh $PATH myscript.sh Here is an example of $PATH from RHEL: $PATH /usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/home/user/bin To change your $PATH you have to either edit ~/.profile (or ~/....

./ Dot Slash not working to execute Shell Scripts

Image
Clash Royale CLAN TAG #URR8PPP ./ Dot Slash not working to execute Shell Scripts I'm definitely a command line novice. I have recently lost the ability to execute shell scripts using ./script.sh I am still able to execute shell scripts using: sh script.sh My $PATH is as follows: /Users/goodguy/.pyenv/shims:/Users/goodguy/.rbenv/shims:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/local/bin:/opt/local/sbin:/Users/goodguy/.rvm/bin I am using MacOS. I'd appreciate any insight into what I may be doing wrong Perhaps it doesn't have the executable flag set. Check with ls -lart script.sh and look for x . You can set it to executable using chmod +x script.sh – Matthew Darnell 14 mins ago ls -lart script.sh x chmod +x script.sh By clicking "Post Your Answer...

Some questions about “-set-xmark” in iptables

Image
Clash Royale CLAN TAG #URR8PPP Some questions about “-set-xmark” in iptables I have a rule as following: -A PREROUTING -d 10.228.20.15/32 -p tcp -m tcp --dport 80--tcp-flags FIN,SYN,RST,ACK SYN -j MARK --set-xmark 0x70/0xffffffff The man doc explains --set-xmark as below: --set-xmark Zero out the bits given by mask and XOR value into the ctmark. English is not my native language. Could anyone help to explain what value would be set into ctmark? What zero out means? Take a example would be appreciated. 2 Answers 2 So the syntax is --set-xmark value/mask . The resulting operation is: --set-xmark value/mask ctmark = (ctmark AND NOT mask) XOR value Zero-out corresponds to (ctmark AND NOT mask) : if a bit in mask is set, then the corresponding bit in ctmark will be zero (before the XOR). (ctmark AND NOT mask) mask ctmark The man page also states: --and-mark bits Binary AND the ctmark with bits....

How to set max size for a specific file in linux

Image
Clash Royale CLAN TAG #URR8PPP How to set max size for a specific file in linux I have an application which will write to a particular log file until the user session is going on. What i am looking for is to put a max cap on the size of a log file so it does not grow beyond a particular size, 2 scenarios which will be useful are Any utility which keeps an eye on the log file and as soon as it reaches the max size start truncating the file content from the start so the application can keep appending the content at the end. Any utility by which while creating the file i can specify the max size of that file and when file reaches that maxsize it should simply not grow beyond that point. What i don't want is man logrotate – Cyrus Dec 17 '17 at 10:46 man logrotate @NiallCosgrove How to put a cap on the size o...

readdir/File::Find::Rule is not reading a subdirectory and its contents in perl

Image
Clash Royale CLAN TAG #URR8PPP readdir/File::Find::Rule is not reading a subdirectory and its contents in perl I have tried 3 different ways to read contents of a folder and none of them are able to identify a subdirectory in a setup. Strange part is, when i recreate the folder structure locally , the sub-directory is identified and i get the file i am looking for with all the 3 solutions. This sub directory is created on the fly along with other files in the folder in the setup. Every time i am able to read all the files which are created but not the sub directory and its contents. I tried below solutions. Solution 1: use File::Find::Rule; my $dir = '.'; my @subdirs = File::Find::Rule->directory->in($dir); foreach (@subdirs) { print "Dir --> $_ n"; } my @list = ("*.txt", "*.rex"); my @files = File::Find::Rule->file()->name(@list)->in(@subdirs); foreach (@files) { print "File --> $_ n"; } --> It does not list t...

Logrotate daily+maxsize is not rotating

Image
Clash Royale CLAN TAG #URR8PPP Logrotate daily+maxsize is not rotating I've CentOS 7.4 with logrotate 3.8.6 installed. I've a custom logrotate file under /etc/logrotate.d/ to rotate some logs on a Tomcat (e.g., catalina.out) which is installed in the same machine. /etc/logrotate.d/ /opt/test/apache-tomcat-8.5.15-client/logs/catalina.out { copytruncate daily rotate 30 olddir /opt/test/apache-tomcat-8.5.15-client/logs/backup compress missingok maxsize 50M dateext dateformat .%Y-%m-%d } I want the log to be rotated daily or if the size reaches 50MB. When this happens log files are compressed and copied into a backup folder and are kept for 30 days before being deleted. I already ran logrotate manually in debug mode with the following command and no errors were displayed (and the expected zipped log files were created): /usr/sbin/logrotate -d /etc/logrotate.d/openncp-tomcat-backoffice 2> /tmp/logrotate.debug /usr/sbin/logrotate -d /etc/logrotate.d/openncp-tomcat-backoffice 2...

No packages marked for update on CentOS 7

Image
Clash Royale CLAN TAG #URR8PPP No packages marked for update on CentOS 7 I have installed Cent OS 7 on my machine. Everything was working fine until today when I entered sudo yum update I receive following - sudo yum update sudo yum update Loaded plugins: fastestmirror, langpacks Loading mirror speeds from cached hostfile * base: centos.mirror.net.in * elrepo: elrepo.reloumirrors.net * epel: mirror.nes.co.id * extras: mirrors.fibergrid.in * nux-dextop: mirror.li.nux.ro * rpmfusion-nonfree-updates: www.mirrorservice.org * updates: mirrors.fibergrid.in No packages marked for update ` I have tried every possible method provided on the internet but I'm still stuck. # CentOS-Base.repo # # The mirror system uses the connecting IP address of the client and the # update status of each mirror to pick mirrors that are updated to and # geographically close to the client. You should use this for CentOS updates # unless you are manually picking other mirrors. # # If the mirrorlist= doe...

Mono (Linux, C#): DLL in same folder can not be found (System.DllNotFoundException)

Image
Clash Royale CLAN TAG #URR8PPP Mono (Linux, C#): DLL in same folder can not be found (System.DllNotFoundException) I am trying to run an C# program on my Raspberry Pi 3 using mono. The program starts correctly, but as soon as I reach a point where I use some OpenCV libraries the program error with the following output: Unhandled Exception: System.TypeInitializationException: The type initializer for 'Emgu.CV.CvInvoke' threw an exception. ---> System.DllNotFoundException: opencv_core220 at (wrapper managed-to-native) Emgu.CV.CvInvoke:cvRedirectError (Emgu.CV.CvInvoke/CvErrorCallback,intptr,intptr) at Emgu.CV.CvInvoke..cctor () [0x00023] in <4f43ef68be294203a100f85f9cebb2b6>:0 --- End of inner exception stack trace --- at Emgu.CV.Image`2[TColor,TDepth].AllocateData (System.Int32 rows, System.Int32 cols, System.Int32 numberOfChannels) [0x0002e] in <4f43ef68be294203a100f85f9cebb2b6>:0 at Emgu.CV.Image`2[TColor,TDepth].set_Bitmap (System.Drawing.Bitmap valu...

Run Python script on Terminal and keep using the terminal afterwards

Image
Clash Royale CLAN TAG #URR8PPP Run Python script on Terminal and keep using the terminal afterwards I have a script that I activate via the terminal that listens to events. I want to keep using the terminal after the script runs, but the script is running and I can't type anything. The only way I know that lets me keep typing is by using the Ctrl + C combination, but this stops the script. So how can I run the script in the background and keep using the terminal without terminating it? That's more of a "how do I use my shell?" question, but you can run commands in the background by adding & to the command line. – melpomene 9 mins ago & Possible duplicate of run a shell script and immediately background it, however keep the ability to inspect its output – Green Cloak ...

Xen domu IO freezes

Image
Clash Royale CLAN TAG #URR8PPP Xen domu IO freezes I installed xen in the Centos 7.4.1708 following the Xen4CentOS guide. And then I installed 3 dom-U guest (2 CentOS7, and 1 Windows server) with full virtualization. After the initial testing when I made system production available, only the linux systems periodically hangs but Windows server system is running alright. The xen kernel is 4.9.63-29.el7.x86_64. The dom-U linux hosts are CentOS 7 (3.10.0-693.5.2.el7.x86_64), and the windows host is Windows Server 2012 R2. The linux kernel for dom-U hosts hangs with the following kernel hang message: > [ 3746.780097] "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message. > [ 3746.780223] INFO: task jbd2/xvdb6-8:8173 blocked for more than 120 seconds. The tasks in above message are different depending what was running at that moment. The logs end at some point until the new reboot. Sometimes it's still possible to log on to the system, but nothing...

Unable to execute include files in PHP Application in Amazon Linux

Image
Clash Royale CLAN TAG #URR8PPP Unable to execute include files in PHP Application in Amazon Linux I'm currently having problem solving why I can't execute inlclude files in my project folder. See /var/logs/httpd/error_log below: Project folder resides at /var/www/payroll /var/www/payroll [Fri Jul 27 05:12:11.793208 2018] [:error] [pid 7904] [client xxx] PHP Warning: include_once(./Controllers/Databasecon.php): failed to open stream: No such file or directory in /var/www/payroll/Controllers/Logout.php on line 2 [Fri Jul 27 05:12:11.793238 2018] [:error] [pid 7904] [client xxx] PHP Warning: include_once(): Failed opening './Controllers/Databasecon.php' for inclusion (include_path='.:/usr/share/pear') in /var/www/payroll/Controllers/Logout.php on line 2 Configured App in VirtualHost <VirtualHost *:80> ServerName binhimefi.com DocumentRoot /var/www <Directory /var/www> DirectoryIndex index.php ...

Linux- Out of Memory

Image
Clash Royale CLAN TAG #URR8PPP Linux- Out of Memory I was trying to see the working of oom_kill by invoking manually. I allocated memory dynamically and tried to use them infinitely with while loop at first and then with the for loop to test out of memory. But in the first case where I used the while loop it threw segmentation fault without swap and became unresponsive with swap whereas with the for loop out of memory (oom_kill) was invoked. Sample codes of both: First case: while: int main (void) { char* p; while (1) { p=malloc(1<<20); memset (p, 0, (1<<20)); } } Second case : for : int main (void) { int i, n = 0; char *pp[N]; for (n = 0; n < N; n++) { pp[n] = malloc(1<<20); if (pp[n] == NULL) break; } printf("malloc failure after %d MiBn", n); for (i = 0; i < n; i++) { ...

Parallel processes: appending outputs to an array in a zsh script

Image
Clash Royale CLAN TAG #URR8PPP Parallel processes: appending outputs to an array in a zsh script I have a for loop in which a function task is called. Each call to the function returns a string that is appended to an array. I would like to parallelise this for loop. I tried using & but it does not seem to work. task & Here is the code not parallelised. task (){ sleep 1;echo "hello $1"; } arr=() for i in {1..3}; do arr+=("$(task $i)") done for i in "${arr[@]}"; do echo "$i x"; done The output is: hello 1 x hello 2 x hello 3 x Great! But now, when I try to parallelise it with [...] for i in {1..3}; do arr+=("$(task $i)")& done wait [...] the output is empty. This question is specifically for zsh , for its bash counterpart please see here. zsh bash 2 Answers 2 I could be wrong, but I'm pretty sure you don't want to do...

NLog works fine on windows .Net Core application but not on Linux

Image
Clash Royale CLAN TAG #URR8PPP NLog works fine on windows .Net Core application but not on Linux I've got this nlog.config file in my .Net Core console application: nlog.config <?xml version="1.0" encoding="utf-8" ?> <nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" autoReload="true" internalLogLevel="Error" internalLogFile="c:tempIBTestinternal-nlog.txt"> <targets> <target xsi:type="File" name="allfile" fileName="c:tempIBTestnlog-all-${shortdate}.log" layout="${longdate}|${event-properties:item=EventId.Id}|${logger}|${uppercase:${level}}|${message} ${exception}" /> <target xsi:type="File" name="ownFile-web" fileName="c:tempIBTestnlog-own-${shortdate}.log" layout="${longdate}|${event-p...

Write a binary file containing zeros to a Linux file system

Image
Clash Royale CLAN TAG #URR8PPP Write a binary file containing zeros to a Linux file system I have a large block of memory in my C program that contains zeros in the middle. I want to save this to disk without converting the values to ASCII. Will writing zeros to a file stream cause a false-negative EOF when I try to read from that file later? Example: int x[1024] = {1, 2, 3, 4, 0, 0, 0, 0, 3}; // write x to disk in myfile.bin Thanks in advance! Not if you use fwrite to write the memory block to a binary file. Next, 0 is not an EOF indicator. Except in some old text file formats (which used 0x1A ), there is no EOF indicator present as part of the file. – Weather Vane 6 mins ago fwrite 0 0x1A 1 Answer 1 ...

C MultiThread Value not printed

C MultiThread Value not printed First, Here is an entire code. 1. Read the file 2. Input file content into structure value 3. Begin Multithread $ cat sunje.conf { DSN:GOLDILOCKS UID:TEST PWD:test COMMIT INTERVAL:1 } $ cat sh.c #include <stdio.h> #include <stdlib.h> #include <string.h> #include <pthread.h> #include <sys/time.h> //EXEC SQL INCLUDE SQLCA; typedef struct thread { char *dsn; char *uid; char *pwd; char mode; int num; int start; int end; int interval; }thread; pthread_mutex_t mutex; void *MultiThread(void* threadInfo); int main(int argc, char **argv) { char s[1024]; FILE *fp; char conn[4][1024]; int i = 0; int session = 0; int record = 0; char mode = NULL; //int interval; fp = fopen("sunje.conf", "r"); while(!feof(fp)) { fgets(s, 1024, fp); char *ptr = strchr(s, ':'); if (ptr != NULL) { strcpy(conn[i], ptr + ...