I would like to know how I check if a directory exists in Nushell?
Use the path exists builtin. Examples:
> "/home" | path exists
true
> "MRE" | path exists
false
> "./nu-0.71.0-x86_64-unknown-linux-gnu" | path exists
true
> [ '.', '/home', 'MRE'] | path exists
╭───┬───────╮
│ 0 │ true │
│ 1 │ true │
│ 2 │ false │
╰───┴───────╯
> if ([ '.', '/home', '/proc'] | path exists | reduce -f true { |it, acc| $acc and $it }) {
"All directories exists"
} else {
"One ore more directories are missing"
}
All directories exists
See help path exists for more details and help path for more path helper builtins.
I have a bash script that generates the following output from a certain input using sed and `awk:
# ├── CHILDA1
# │ └── CHILDB1
# │ └── CHILDB2
# │ └── CHILDB3
# │ └── CHILDB4
# │ └── CHILDB5
# │ └── CHILDB6
# │ └── CHILDC1
# │ └── CHILDC2
# │ └── CHILDB7
# ├── CHILDA2
# └──────────────
Is there a way to replace the nest connectors, if they are not the last one, in order to obtain something like this?
# ├──┐CHILDA1
# │ ├── CHILDB1
# │ ├── CHILDB2
# │ ├── CHILDB3
# │ ├── CHILDB4
# │ ├── CHILDB5
# │ ├──┐CHILDB6
# │ │ ├── CHILDC1
# │ │ └── CHILDC2
# │ └── CHILDB7
# ├── CHILDA2
# └──────────────
The first output has been obtained with simple single lines substitutions, I guess the second one needs to check for the row above at the same column (character position). I don't know how tree handles this, but the result I would like to obtain is very similar.
Unicode characters obtained from https://en.wikipedia.org/wiki/Box_Drawing
It would be easier to process the file from the bottom up. This can be achieved using tac.
Through #flags, the following tracks the position of children whose parent has not yet been encountered.
tac |
perl -CSD -Mutf8 -pe'
if ( /[└├]/ ) {
my $i = $-[0]; # Position of the match.
substr($_, $i, 1, "├") if $flags[$i];
$flags[$i] = 1;
my $j = $i+3; # Position of its children.
substr($_, $j, 1, "┐") if $flags[$j];
$flags[$j] = 0;
while ( $i-- ) {
substr($_, $i, 1, "│") if $flags[$i];
}
}
' |
tac
Output
# ├── CHILDA1
# │ ├── CHILDB1
# │ ├── CHILDB2
# │ ├── CHILDB3
# │ ├── CHILDB4
# │ ├── CHILDB5
# │ ├──┐CHILDB6
# │ │ ├── CHILDC1
# │ │ └── CHILDC2
# │ └── CHILDB7
# ├── CHILDA2
# └──────────────
All in Perl:
perl -CSD -Mutf8 -e'
my #lines = reverse <>;
for ( #lines ) {
if ( /[└├]/ ) {
my $i = $-[0]; # Position of the match.
substr($_, $i, 1, "├") if $flags[$i];
$flags[$i] = 1;
my $j = $i+3; # Position of its children.
substr($_, $j, 1, "┐") if $flags[$j];
$flags[$j] = 0;
while ( $i-- ) {
substr($_, $i, 1, "│") if $flags[$i];
}
}
}
print reverse #lines;
'
this is my first question.
I'm confusing on my IntelliJ Idea hanging 1 minute when starting and debugging with network on. Could anyone help me? Thanks.
I have tried IntelliJC and IntelliJU which are both 15.0.4. When I cut down the network, It works with no problem. But, with network on, it becomes hanging when starting and debugging.
Through logs, I found that there's almost 1 minute between I starting IntelliJ and its log beginning.
I even captured its network packets, found nothing, there was no connection.
I'm using Macbook, and I found the system log:
Mar 11 07:49:36 Coderec's MBP idea[1867]: Value of IDEA_JDK: (null)
Mar 11 07:49:36 Coderec's MBP idea[1867]: fullFileName is: /Applications/IntelliJ IDEA 15 CE.app/Contents/bin/idea.vmoptions
Mar 11 07:49:36 Coderec's MBP idea[1867]: fullFileName exists: /Applications/IntelliJ IDEA 15 CE.app/Contents/bin/idea.vmoptions
Mar 11 07:49:36 Coderec's MBP idea[1867]: Value of IDEA_VM_OPTIONS is (null)
Mar 11 07:49:36 Coderec's MBP idea[1867]: Processing VMOptions file at /Applications/IntelliJ IDEA 15 CE.app/Contents/bin/idea.vmoptions
Mar 11 07:49:36 Coderec's MBP idea[1867]: Done
and the IntelliJ log:
2016-03-11 07:50:37,529 [ 60385] INFO - #com.intellij.idea.Main - ------------------------------------------------------ IDE STARTED ------------------------------------------------------
2016-03-11 07:50:37,559 [ 60415] INFO - #com.intellij.idea.Main - IDE: IntelliJ IDEA (build #IC-143.2287.1, 23 Feb 2016 00:00)
2016-03-11 07:50:37,559 [ 60415] INFO - #com.intellij.idea.Main - OS: Mac OS X (10.11.3, x86_64)
2016-03-11 07:50:37,559 [ 60415] INFO - #com.intellij.idea.Main - JRE: 1.8.0_40-release-b132 (JetBrains s.r.o)
2016-03-11 07:50:37,559 [ 60415] INFO - #com.intellij.idea.Main - JVM: 25.40-b25 (OpenJDK 64-Bit Server VM)
2016-03-11 07:50:37,560 [ 60416] INFO - #com.intellij.idea.Main - JVM Args: -Dfile.encoding=UTF-8 -XX:+UseConcMarkSweepGC -XX:SoftRefLRUPolicyMSPerMB=50 -ea -Dsun.io.useCanonCaches=false -Djava.net.preferIPv4Stack=true -XX:+HeapDumpOnOutOfMemoryError -XX:-OmitStackTraceInFastThrow -Xverify:none -Xbootclasspath/a:../lib/boot.jar -Xms128m -Xmx750m -XX:MaxPermSize=350m -XX:ReservedCodeCacheSize=240m -XX:+UseCompressedOops -Djb.vmOptionsFile=/Applications/IntelliJ IDEA 15 CE.app/Contents/bin/idea.vmoptions -Didea.java.redist=custom-jdk-bundled -Didea.home.path=/Applications/IntelliJ IDEA 15 CE.app/Contents -Didea.executable=idea -Didea.paths.selector=IdeaIC15
2016-03-11 07:50:37,561 [ 60417] INFO - #com.intellij.idea.Main - ext: /Applications/IntelliJ IDEA 15 CE.app/Contents/jre/jdk/Contents/Home/jre/lib/ext: [cldrdata.jar, dnsns.jar, jaccess.jar, jfxrt.jar, localedata.jar, meta-index, nashorn.jar, sunec.jar, sunjce_provider.jar, sunpkcs11.jar, zipfs.jar]
2016-03-11 07:50:37,561 [ 60417] INFO - #com.intellij.idea.Main - ext: /System/Library/Java/Extensions: [MRJToolkit.jar]
2016-03-11 07:50:37,581 [ 60437] INFO - #com.intellij.idea.Main - JNA library loaded (64-bit) in 20 ms
2016-03-11 07:50:37,584 [ 60440] INFO - #com.intellij.idea.Main - initializing environment
2016-03-11 07:50:37,585 [ 60441] INFO - .intellij.util.EnvironmentUtil - loading shell env: /bin/zsh -l -i -c '/Applications/IntelliJ IDEA 15 CE.app/Contents/bin/printenv.py' '/private/var/folders/w9/rkmh4kqs2l3bd5nf5mlp7k100000gq/T/intellij-shell-env.0.tmp'
2016-03-11 07:50:38,546 [ 61402] INFO - .intellij.util.EnvironmentUtil - shell environment loaded (19 vars)
2016-03-11 07:50:38,784 [ 61640] INFO - llij.ide.plugins.PluginManager - Cannot find optional descriptor duplicates-groovy.xml
2016-03-11 07:50:39,050 [ 61906] INFO - llij.ide.plugins.PluginManager - 31 plugins initialized in 436 ms
2016-03-11 07:50:39,052 [ 61908] INFO - llij.ide.plugins.PluginManager - Loaded bundled plugins: Android Support (10.1.3.0), Ant Support (1.0), Bytecode Viewer (0.1), CVS Integration (11), Copyright (8.1), Coverage (143.SNAPSHOT), Eclipse Integration (3.0), EditorConfig (1.0), Git Integration (8.1), GitHub (143.2287.1), Gradle (143.2287.1), Groovy (9.0), I18n for Java (143.2287.1), IDEA CORE (143.SNAPSHOT), IntelliLang (8.0), JUnit (1.0), Java Bytecode Decompiler (0.1), JavaFX (1.0), Kotlin (1.0.0-release-IJ143-75), Maven Integration (143.2287.1), Plugin DevKit (1.0), Properties Support (143.SNAPSHOT), Settings Repository (143.2287.1), Subversion Integration (1.1), Task Management (1.0), Terminal (0.1), TestNG-J (8.0), UI Designer (143.2287.1), XPathView + XSLT Support (4), XSLT-Debugger (1.4), hg4idea (10.0)
2016-03-11 07:50:39,384 [ 62240] INFO - ellij.util.io.PagedFileStorage - lower=100; upper=500; buffer=10; max=739246080
2016-03-11 07:50:39,415 [ 62271] INFO - pl.local.NativeFileWatcherImpl - Starting file watcher: /Applications/IntelliJ IDEA 15 CE.app/Contents/bin/fsnotifier
2016-03-11 07:50:39,423 [ 62279] INFO - pl.local.NativeFileWatcherImpl - Native file watcher is operational.
2016-03-11 07:50:40,025 [ 62881] INFO - rains.ide.BuiltInServerManager - built-in server started, port 63342
2016-03-11 07:50:40,564 [ 63420] INFO - plication.impl.ApplicationImpl - 84 application components initialized in 1951 ms
2016-03-11 07:50:40,581 [ 63437] INFO - .intellij.idea.IdeaApplication - App initialization took 63756 ms
2016-03-11 07:50:40,588 [ 63444] INFO - ntellij.util.proxy.CommonProxy - <html>You have JVM property "socksProxyHost" set to "127.0.0.1".<br>This may lead to incorrect behaviour. Proxy should be set in Settings | HTTP Proxy<br>This JVM property is old and its usage is not recommended by Oracle.<br>(Note: It could have been assigned by some code dynamically.)
2016-03-11 07:50:40,647 [ 63503] INFO - ntellij.util.proxy.CommonProxy - <html>You have JVM property "socksProxyHost" set to "127.0.0.1".<br>This may lead to incorrect behaviour. Proxy should be set in Settings | HTTP Proxy<br>This JVM property is old and its usage is not recommended by Oracle.<br>(Note: It could have been assigned by some code dynamically.)
2016-03-11 07:50:41,176 [ 64032] INFO - CompilerWorkspaceConfiguration - Available processors: 8
2016-03-11 07:50:41,575 [ 64431] INFO - ellij.project.impl.ProjectImpl - 148 project components initialized in 746 ms
2016-03-11 07:50:41,723 [ 64579] INFO - le.impl.ModuleManagerComponent - 2 module(s) loaded in 147 ms
2016-03-11 07:50:43,450 [ 66306] INFO - tartup.impl.StartupManagerImpl - /Users/coderec/IdeaProjects/pttms-server/pttms-server/.idea/misc.xml case-sensitivity: false
2016-03-11 07:50:44,351 [ 67207] INFO - .diagnostic.PerformanceWatcher - Pushing properties took 22ms; general responsiveness: ok; EDT responsiveness: ok
2016-03-11 07:50:44,934 [ 67790] INFO - tor.impl.FileEditorManagerImpl - Project opening took 4133 ms
2016-03-11 07:50:45,903 [ 68759] INFO - .diagnostic.PerformanceWatcher - Indexable file iteration took 1551ms; general responsiveness: ok; EDT responsiveness: ok
2016-03-11 07:50:46,373 [ 69229] INFO - lij.tasks.impl.TaskManagerImpl - Updating issues cache (every 20 min)
2016-03-11 07:50:47,309 [ 70165] INFO - j.compiler.server.BuildManager - BUILDER_PROCESS [stdout]: Build process started. Classpath: /Applications/IntelliJ IDEA 15 CE.app/Contents/lib/jps-launcher.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_51.jdk/Contents/Home/lib/tools.jar:/Applications/IntelliJ IDEA 15 CE.app/Contents/lib/optimizedFileManager.jar:/Applications/IntelliJ IDEA 15 CE.app/Contents/lib/ecj-4.4.jar
2016-03-11 07:50:47,678 [ 70534] INFO - ution.rmi.RemoteProcessSupport - "/Applications/IntelliJ IDEA 15 CE.app/Contents/jre/jdk/Contents/Home/jre/bin/java" -d64 -Djava.awt.headless=true -Didea.version==15.0.4 -Xmx512m -Didea.maven.embedder.version=3.0.5 -Dfile.encoding=UTF-8 -classpath "/Applications/IntelliJ IDEA 15 CE.app/Contents/lib/resources_en.jar:/Applications/IntelliJ IDEA 15 CE.app/Contents/lib/log4j.jar:/Applications/IntelliJ IDEA 15 CE.app/Contents/lib/slf4j-api-1.7.10.jar:/Applications/IntelliJ IDEA 15 CE.app/Contents/lib/slf4j-log4j12-1.7.10.jar:/Applications/IntelliJ IDEA 15 CE.app/Contents/lib/jna-platform.jar:/Applications/IntelliJ IDEA 15 CE.app/Contents/lib/snappy-in-java-0.3.1.jar:/Applications/IntelliJ IDEA 15 CE.app/Contents/lib/picocontainer.jar:/Applications/IntelliJ IDEA 15 CE.app/Contents/lib/jna.jar:/Applications/IntelliJ IDEA 15 CE.app/Contents/lib/oromatcher.jar:/Applications/IntelliJ IDEA 15 CE.app/Contents/lib/annotations.jar:/Applications/IntelliJ IDEA 15 CE.app/Contents/lib/trove4j.jar:/Applications/IntelliJ IDEA 15 CE.app/Contents/lib/jdom.jar:/Applications/IntelliJ IDEA 15 CE.app/Contents/lib/util.jar:/Applications/IntelliJ IDEA 15 CE.app/Contents/plugins/maven/lib/lucene-core-2.4.1.jar:/Applications/IntelliJ IDEA 15 CE.app/Contents/plugins/maven/lib/maven-server-api.jar:/Applications/IntelliJ IDEA 15 CE.app/Contents/plugins/maven/lib/maven3-server-common.jar:/Applications/IntelliJ IDEA 15 CE.app/Contents/plugins/maven/lib/maven3-server-lib/archetype-catalog-2.2.jar:/Applications/IntelliJ IDEA 15 CE.app/Contents/plugins/maven/lib/maven3-server-lib/archetype-common-2.2.jar:/Applications/IntelliJ IDEA 15 CE.app/Contents/plugins/maven/lib/maven3-server-lib/maven-dependency-tree-1.2.jar:/Applications/IntelliJ IDEA 15 CE.app/Contents/plugins/maven/lib/maven3-server-lib/nexus-indexer-3.0.4.jar:/Applications/IntelliJ IDEA 15 CE.app/Contents/plugins/maven/lib/maven3-server-lib/nexus-indexer-artifact-1.0.1.jar:/Applications/IntelliJ IDEA 15 CE.app/Contents/plugins/maven/lib/maven30-server-impl.jar:/Applications/IntelliJ IDEA 15 CE.app/Contents/plugins/maven/lib/maven3/lib/aether-api-1.13.1.jar:/Applications/IntelliJ IDEA 15 CE.app/Contents/plugins/maven/lib/maven3/lib/aether-connector-wagon-1.13.1.jar:/Applications/IntelliJ IDEA 15 CE.app/Contents/plugins/maven/lib/maven3/lib/aether-impl-1.13.1.jar:/Applications/IntelliJ IDEA 15 CE.app/Contents/plugins/maven/lib/maven3/lib/aether-spi-1.13.1.jar:/Applications/IntelliJ IDEA 15 CE.app/Contents/plugins/maven/lib/maven3/lib/aether-util-1.13.1.jar:/Applications/IntelliJ IDEA 15 CE.app/Contents/plugins/maven/lib/maven3/lib/commons-cli-1.2.jar:/Applications/IntelliJ IDEA 15 CE.app/Contents/plugins/maven/lib/maven3/lib/commons-io-2.2.jar:/Applications/IntelliJ IDEA 15 CE.app/Contents/plugins/maven/lib/maven3/lib/commons-lang-2.6.jar:/Applications/IntelliJ IDEA 15 CE.app/Contents/plugins/maven/lib/maven3/lib/maven-aether-provider-3.0.5.jar:/Applications/IntelliJ IDEA 15 CE.app/Contents/plugins/maven/lib/maven3/lib/maven-artifact-3.0.5.jar:/Applications/IntelliJ IDEA 15 CE.app/Contents/plugins/maven/lib/maven3/lib/maven-compat-3.0.5.jar:/Applications/IntelliJ IDEA 15 CE.app/Contents/plugins/maven/lib/maven3/lib/maven-core-3.0.5.jar:/Applications/IntelliJ IDEA 15 CE.app/Contents/plugins/maven/lib/maven3/lib/maven-embedder-3.0.5.jar:/Applications/IntelliJ IDEA 15 CE.app/Contents/plugins/maven/lib/maven3/lib/maven-model-3.0.5.jar:/Applications/IntelliJ IDEA 15 CE.app/Contents/plugins/maven/lib/maven3/lib/maven-model-builder-3.0.5.jar:/Applications/IntelliJ IDEA 15 CE.app/Contents/plugins/maven/lib/maven3/lib/maven-plugin-api-3.0.5.jar:/Applications/IntelliJ IDEA 15 CE.app/Contents/plugins/maven/lib/maven3/lib/maven-repository-metadata-3.0.5.jar:/Applications/IntelliJ IDEA 15 CE.app/Contents/plugins/maven/lib/maven3/lib/maven-settings-3.0.5.jar:/Applications/IntelliJ IDEA 15 CE.app/Contents/plugins/maven/lib/maven3/lib/maven-settings-builder-3.0.5.jar:/Applications/IntelliJ IDEA 15 CE.app/Contents/plugins/maven/lib/maven3/lib/plexus-cipher-1.7.jar:/Applications/IntelliJ IDEA 15 CE.app/Contents/plugins/maven/lib/maven3/lib/plexus-component-annotations-1.5.5.jar:/Applications/IntelliJ IDEA 15 CE.app/Contents/plugins/maven/lib/maven3/lib/plexus-interpolation-1.14.jar:/Applications/IntelliJ IDEA 15 CE.app/Contents/plugins/maven/lib/maven3/lib/plexus-sec-dispatcher-1.3.jar:/Applications/IntelliJ IDEA 15 CE.app/Contents/plugins/maven/lib/maven3/lib/plexus-utils-2.0.6.jar:/Applications/IntelliJ IDEA 15 CE.app/Contents/plugins/maven/lib/maven3/lib/sisu-guava-0.9.9.jar:/Applications/IntelliJ IDEA 15 CE.app/Contents/plugins/maven/lib/maven3/lib/sisu-guice-3.1.0-no_aop.jar:/Applications/IntelliJ IDEA 15 CE.app/Contents/plugins/maven/lib/maven3/lib/sisu-inject-bean-2.3.0.jar:/Applications/IntelliJ IDEA 15 CE.app/Contents/plugins/maven/lib/maven3/lib/sisu-inject-plexus-2.3.0.jar:/Applications/IntelliJ IDEA 15 CE.app/Contents/plugins/maven/lib/maven3/lib/wagon-file-2.8.jar:/Applications/IntelliJ IDEA 15 CE.app/Contents/plugins/maven/lib/maven3/lib/wagon-http-2.8-shaded.jar:/Applications/IntelliJ IDEA 15 CE.app/Contents/plugins/maven/lib/maven3/lib/wagon-http-shared-2.8.jar:/Applications/IntelliJ IDEA 15 CE.app/Contents/plugins/maven/lib/maven3/lib/wagon-provider-api-2.8.jar:/Applications/IntelliJ IDEA 15 CE.app/Contents/plugins/maven/lib/maven3/boot/plexus-classworlds-2.4.jar" org.jetbrains.idea.maven.server.RemoteMavenServer
2016-03-11 07:50:47,917 [ 70773] INFO - ution.rmi.RemoteProcessSupport - Port/ID: 4823/Maven30ServerImplf51fe04a
2016-03-11 07:50:48,891 [ 71747] INFO - ution.rmi.RemoteProcessSupport - 0 [RMI TCP Connection(3)-127.0.0.1] DEBUG Sisu - Add publisher: com.google.inject.internal.InjectorImpl#5fd5172c
2016-03-11 07:50:48,891 [ 71747] INFO - ution.rmi.RemoteProcessSupport -
2016-03-11 07:50:48,891 [ 71747] INFO - ution.rmi.RemoteProcessSupport - -----[explicit bindings]-------------------------------------------------------
2016-03-11 07:50:48,891 [ 71747] INFO - ution.rmi.RemoteProcessSupport - 0. ProviderInstanceBinding{key=Key[type=com.google.inject.Injector, annotation=[none]], source=[unknown source], scope=Scopes.NO_SCOPE, provider=Provider<Injector>}
2016-03-11 07:50:48,891 [ 71747] INFO - ution.rmi.RemoteProcessSupport - 1. ProviderInstanceBinding{key=Key[type=java.util.logging.Logger, annotation=[none]], source=[unknown source], scope=Scopes.NO_SCOPE, provider=Provider<Logger>}
2016-03-11 07:50:48,891 [ 71747] INFO - ution.rmi.RemoteProcessSupport - 2. ProviderInstanceBinding{key=Key[type=org.slf4j.Logger, annotation=[none]], source=[unknown source], scope=Scopes.NO_SCOPE, provider=Provider<org.slf4j.Logger>}
2016-03-11 07:50:48,891 [ 71747] INFO - ution.rmi.RemoteProcessSupport - 3. InstanceBinding{key=Key[type=com.google.inject.Stage, annotation=[none]], source=[unknown source], instance=DEVELOPMENT}
2016-03-11 07:50:48,891 [ 71747] INFO - ution.rmi.RemoteProcessSupport - 4. InstanceBinding{key=Key[type=org.codehaus.plexus.context.Context, annotation=[none]], source=org.codehaus.plexus.DefaultPlexusContainer$ContainerModule.configure(DefaultPlexusContainer.java:800), instance={plexus=org.codehaus.plexus.DefaultPlexusContainer#290238e6}}
2016-03-11 07:50:48,891 [ 71747] INFO - ution.rmi.RemoteProcessSupport - 5. InstanceBinding{key=Key[type=java.util.Map, annotation=#org.sonatype.inject.Parameters], source=org.codehaus.plexus.DefaultPlexusContainer$ContainerModule.configure(DefaultPlexusContainer.java:801), instance=null}
2016-03-11 07:50:48,891 [ 71747] INFO - ution.rmi.RemoteProcessSupport - 6. InstanceBinding{key=Key[type=org.sonatype.guice.bean.locators.MutableBeanLocator, annotation=[none]], source=org.codehaus.plexus.DefaultPlexusContainer$ContainerModule.configure(DefaultPlexusContainer.java:803), instance=org.sonatype.guice.bean.locators.DefaultBeanLocator#47715323[Locked by thread RMI TCP Connection(3)-127.0.0.1]}
6~235, omitted
2016-03-11 07:50:48,904 [ 71760] INFO - ution.rmi.RemoteProcessSupport - 235. ConstructorBinding{key=Key[type=org.apache.maven.lifecycle.internal.LifecyclePluginResolver, annotation=[none]], source=ClassRealm[plexus.core, parent: null], scope=Scopes.SINGLETON}
2016-03-11 07:50:48,904 [ 71760] INFO - ution.rmi.RemoteProcessSupport - 236. ConstructorBinding{key=Key[type=org.apache.maven.lifecycle.internal.LifecycleThreadedBuilder, annotation=[none]], source=ClassRealm[plexus.core, parent: null], scope=Scopes.SINGLETON}
2016-03-11 07:50:48,904 [ 71760] INFO - ution.rmi.RemoteProcessSupport - 237. ConstructorBinding{key=Key[type=org.apache.maven.lifecycle.internal.MojoDescriptorCreator, annotation=[none]], source=ClassRealm[plexus.core, parent: null], scope=Scopes.SINGLETON}
2016-03-11 07:50:48,904 [ 71760] INFO - ution.rmi.RemoteProcessSupport - -----[implicit bindings]-------------------------------------------------------
2016-03-11 07:50:48,904 [ 71760] INFO - ution.rmi.RemoteProcessSupport - -------------------------------------------------------------------------------
2016-03-11 07:50:48,904 [ 71760] INFO - ution.rmi.RemoteProcessSupport -
2016-03-11 07:50:49,935 [ 72791] INFO - j.compiler.server.BuildManager - BUILDER_PROCESS [stdout]: Build process started. Classpath: /Applications/IntelliJ IDEA 15 CE.app/Contents/lib/jps-launcher.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_51.jdk/Contents/Home/lib/tools.jar:/Applications/IntelliJ IDEA 15 CE.app/Contents/lib/optimizedFileManager.jar:/Applications/IntelliJ IDEA 15 CE.app/Contents/lib/ecj-4.4.jar
I finally solved this problem with resetting the host name of my mac, which was set with blank like "Coderec's MBP".
The illegal host name caused this confusing problem.
I have this script
rename_files() {
title="${1##*${2} - }"
for filename in "$1/"*.*; do
case "${filename##*.}" in
ext1|ext2|ext3)
mkdir "/User/Downloaded/${title}"
new_path="/User/Downloaded/${title}/${title}.${filename##*.}"
echo "moving $filename -> $new_path"
mv "$filename" "$new_path"
;;
esac
done
}
rename_category() {
for path in "/User/Downloads/${1}"*; do
rename_files "$path" "$1"
done
}
rename_category CAT1
rename_category CAT2
That do this
Before
.
├── Downloads
│ ├── CAT1 - Something ── File.ext1
│ └── CAT2 - SomethingElse ── OtherFile.ext1
├── Downloaded
├── CAT1
├── CAT2
After
.
├── Downloads
│ ├── CAT1 - Something
│ └── CAT2 - SomethingElse
├── Downloaded
├── CAT1 ── Something ── Something.ext1
├── CAT2 ── SomethingElse ── SomethingElse.ext1
What I'm trying to do is that if only there's more that one file with the same extension, then these files will be renamed adding _1, etc.
Before
.
├── Downloads
│ ├── CAT1 - Something ├── File.ext1
├── ExampleFile.ext1
│ └── CAT2 - SomethingElse ── OtherFile.ext1
├── Downloaded
├── CAT1
├── CAT2
After
.
├── Downloads
│ ├── CAT1 - Something
│ └── CAT2 - SomethingElse
├── Downloaded
├── CAT1 ── Something ── Something_1.ext1
── Something_2.ext1
├── CAT2 ── SomethingElse ── SomethingElse.ext1
EDIT:
#!/bin/bash
rename_files() {
title="${1##*${2} - }"
for filename in "$1/"*.*; do
case "${filename##*.}" in
doc|ext|ext)
mkdir "/User/Downloaded/${title}"
new_path="/User/Downloaded/${title}/${title}.${filename##*.}"
let "iters=1"
while [ -f $new_path ] ; do
$new_path=$new_path"$iters"
let "iters++"
done
echo "moving $filename -> $new_path"
mv "$filename" "$new_path"
;;
esac
done
}
rename_category() {
for path in "/User/Downloads/${1}"*; do
rename_files "$path" "$1"
done
}
rename_category CAT1
EDIT2:
There are two .doc files in /User/Downloads/DOC - TEST
/User/Downloads/DOC - TEST/Sample-doc-file-100kb.doc
/Sample-doc-file-200kb.doc
What I want is
/User/Downloaded/TEST/TEST_1.doc
/TEST_2.doc
This is the output log
chmod +x /User/TEST.sh
sh /User/TEST.sh
moving /User/Downloads/DOC - TEST/Sample-doc-file-100kb.doc -> /User/Downloaded/TEST/TEST.doc
mkdir: /User/Downloaded/TEST: File exists
/User/TEST.sh: line 12: /User/Downloaded/TEST/TEST.doc=/User/Downloaded/TEST/TEST.doc1: No such file or directory
/User/TEST.sh: line 12: /User/Downloaded/TEST/TEST.doc=/User/Downloaded/TEST/TEST.doc2: No such file or directory
etc.
Updated output log
sh /User/Script.sh
moving /User/Downloads/DOC - TEST/Sample-doc-file-100kb.doc -> /User/Downloaded/TEST/TEST.doc
mv: rename {/User/Downloads/DOC - TEST/Sample-doc-file-100kb.doc} to {/User/Downloaded/TEST/TEST.doc}: No such file or directory
mkdir: /User/Downloaded/TEST: File exists
moving /User/Downloads/DOC - TEST/Sample-doc-file-200kb.doc -> /User/Downloaded/TEST/TEST.doc
mv: rename {/User/Downloads/DOC - TEST/Sample-doc-file-200kb.doc} to {/User/Downloaded/TEST/TEST.doc}: No such file or directory
OUTPUT UPDATED:
Here is my initial situation
User/Downloads/DOC - TEST/SampleDoc.doc
/OtherSampleDoc.doc
/OtherDoc.doc
User/Downloaded/
After the script I only obtain
User/Downloads/DOC - TEST/OtherSampleDoc.doc
/OtherDoc.doc
User/Downloaded/TEST/TEST.doc
But want I want would be
User/Downloads/DOC - TEST
User/Downloaded/TEST/TEST_1.doc
/TEST_2.doc
/TEST_3.doc
And this is the output
sh /User/Script.sh
moving /User/Downloads/DOC - TEST/OtherDoc.doc -> /User/Downloaded/TEST/TEST.doc
mkdir: /User/Downloaded/TEST: File exists
/User/Script.sh: line 12: /User/Downloaded/TEST/TEST.doc=/User/Downloaded/TEST/TEST.doc1: No such file or directory
/User/Script.sh: line 12: /User/Downloaded/TEST/TEST.doc=/User/Downloaded/TEST/TEST.doc2: No such file or directory
/User/Script.sh: line 12: /User/Downloaded/TEST/TEST.doc=/User/Downloaded/TEST/TEST.doc3: No such file or directory
etc.
rename_files() {
title="${1##*${2} - }"
for filename in "$1/"*.*; do
case "${filename##*.}" in
ext1|ext2|ext3)
mkdir "/User/Downloaded/${title}"
new_path="/User/Downloaded/${title}/${title}.${filename##*.}"
let "iters=1"
while [ -f $new_path ] ; do
new_path=$new_path"$iters"
let "iters++"
done
echo "moving $filename -> $new_path"
mv "${filename}" "${new_path}"
;;
esac
done
}
I setup a cronjob to call myscript.sh every 5 min which then calls a php file between 30 sec and 3 in time and I don't get it why the average Interval is 05:09.
I want to call cron2_.php every 4-8 min but no chance to achieve that.
Tank you.
Cron Job: */5 * * * * myscript.sh
Shell script:
#!/bin/sh
# Grab a random value between 60-180 or ( between 30sec and 3 minutes )
value=$RANDOM
while [ $value -gt 180 ] || [ $value -lt 30 ] ;
do
value=$RANDOM
done
# Sleep for that time.
sleep $value
# Exectue Cron.
echo "Exectued on:$(date)" >> public_html/log_file.txt
exec php -f public_html/cron2_.php
Here is the exectuion time for 2 hours:
Average Interval -> 05:09
Execution Time Interval Min:Sec
13:02:52 00:00
13:07:06 04:14
13:11:35 04:29
13:17:34 05:59
13:21:55 04:21
13:26:54 04:59
13:32:00 05:06
13:35:50 03:50
13:42:44 06:54
13:47:03 04:19
13:51:26 04:23
13:56:48 05:22
14:01:53 05:05
14:07:42 05:49
14:12:15 04:33
14:16:22 04:07
14:23:01 06:39
14:27:17 04:16
14:32:21 05:04
14:35:57 03:36
14:42:14 06:17
14:45:44 03:30
14:52:52 07:08
14:56:50 03:58
15:02:57 06:07
15:06:43 03:46
15:12:26 05:43
15:16:29 04:03
15:22:00 05:31
15:25:35 03:35
15:31:51 06:16
15:37:51 06:00
15:42:56 05:05
15:47:32 04:36
15:50:36 03:04
15:55:45 05:09
16:02:15 06:30
16:06:10 03:55
16:11:11 05:01
16:15:56 04:45
16:21:58 06:02
16:25:56 03:58
16:31:09 05:13
16:37:06 05:57
16:42:30 05:24
16:45:36 03:06
You want your script to run every 4 to 8 minutes. Let's say then that we want, on average, one execution every 6 minutes. In that case, set the crontab line to:
*/6 * * * * myscript.sh
Next, in your script, put a random delay of zero to two minutes:
sleep $(($RANDOM % 120))
Consider two extreme cases. First, suppose that one job waits the maximum 2 minutes and the next waits the minimum of 0 minutes. The time between their executions is 4 minutes. For the second case, consider the opposite: the first job waits the minimum of 0 minutes and the second waits the maximum of 2 minutes. In this case, the time between their executions is 8 minutes. Thus, this approach achieves a wait of 4 to 8 minutes with an average wait of 6 minutes.